1
0
mirror of https://github.com/RPCS3/soundtouch.git synced 2024-11-09 20:33:03 +01:00

Merge pull request 'Fix exception throwing across DLL boundary' (#2) from sagamusix/soundtouch:master into master

Reviewed-on: https://codeberg.org/soundtouch/soundtouch/pulls/2
This commit is contained in:
Olli Parviainen 2022-01-23 16:08:35 +01:00
commit 9f14bd8b6e
3 changed files with 57 additions and 17 deletions

1
.gitignore vendored
View File

@ -38,6 +38,7 @@ source/SoundTouchDll/Win32/
source/SoundTouchDll/x64/ source/SoundTouchDll/x64/
source/SoundTouchDll/DllTest/Win32/ source/SoundTouchDll/DllTest/Win32/
source/SoundTouchDll/DllTest/x64/ source/SoundTouchDll/DllTest/x64/
.vs
# Files generated by Android Studio # Files generated by Android Studio
source/android-lib/.gradle source/android-lib/.gradle

View File

@ -207,22 +207,38 @@ SOUNDTOUCHDLL_API void __cdecl soundtouch_setPitchSemiTones(HANDLE h, float newP
/// Sets the number of channels, 1 = mono, 2 = stereo /// Sets the number of channels, 1 = mono, 2 = stereo
SOUNDTOUCHDLL_API void __cdecl soundtouch_setChannels(HANDLE h, uint numChannels) SOUNDTOUCHDLL_API int __cdecl soundtouch_setChannels(HANDLE h, uint numChannels)
{ {
STHANDLE *sth = (STHANDLE*)h; STHANDLE *sth = (STHANDLE*)h;
if (sth->dwMagic != STMAGIC) return; if (sth->dwMagic != STMAGIC) return 0;
try
{
sth->pst->setChannels(numChannels); sth->pst->setChannels(numChannels);
} }
catch (const std::exception&)
{
return 0;
}
return 1;
}
/// Sets sample rate. /// Sets sample rate.
SOUNDTOUCHDLL_API void __cdecl soundtouch_setSampleRate(HANDLE h, uint srate) SOUNDTOUCHDLL_API int __cdecl soundtouch_setSampleRate(HANDLE h, uint srate)
{ {
STHANDLE *sth = (STHANDLE*)h; STHANDLE *sth = (STHANDLE*)h;
if (sth->dwMagic != STMAGIC) return; if (sth->dwMagic != STMAGIC) return 0;
try
{
sth->pst->setSampleRate(srate); sth->pst->setSampleRate(srate);
} }
catch (const std::exception&)
{
return 0;
}
return 1;
}
/// Flushes the last samples from the processing pipeline to the output. /// Flushes the last samples from the processing pipeline to the output.
/// Clears also the internal processing buffers. /// Clears also the internal processing buffers.
@ -231,18 +247,26 @@ SOUNDTOUCHDLL_API void __cdecl soundtouch_setSampleRate(HANDLE h, uint srate)
/// stream. This function may introduce additional blank samples in the end /// stream. This function may introduce additional blank samples in the end
/// of the sound stream, and thus it's not recommended to call this function /// of the sound stream, and thus it's not recommended to call this function
/// in the middle of a sound stream. /// in the middle of a sound stream.
SOUNDTOUCHDLL_API void __cdecl soundtouch_flush(HANDLE h) SOUNDTOUCHDLL_API int __cdecl soundtouch_flush(HANDLE h)
{ {
STHANDLE *sth = (STHANDLE*)h; STHANDLE *sth = (STHANDLE*)h;
if (sth->dwMagic != STMAGIC) return; if (sth->dwMagic != STMAGIC) return 0;
try
{
sth->pst->flush(); sth->pst->flush();
} }
catch (const std::exception&)
{
return 0;
}
return 1;
}
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into /// Adds 'numSamples' pcs of samples from the 'samples' memory position into
/// the input of the object. Notice that sample rate _has_to_ be set before /// the input of the object. Notice that sample rate _has_to_ be set before
/// calling this function, otherwise throws a runtime_error exception. /// calling this function, otherwise throws a runtime_error exception.
SOUNDTOUCHDLL_API void __cdecl soundtouch_putSamples(HANDLE h, SOUNDTOUCHDLL_API int __cdecl soundtouch_putSamples(HANDLE h,
const SAMPLETYPE *samples, ///< Pointer to sample buffer. const SAMPLETYPE *samples, ///< Pointer to sample buffer.
unsigned int numSamples ///< Number of samples in buffer. Notice unsigned int numSamples ///< Number of samples in buffer. Notice
///< that in case of stereo-sound a single sample ///< that in case of stereo-sound a single sample
@ -250,10 +274,18 @@ SOUNDTOUCHDLL_API void __cdecl soundtouch_putSamples(HANDLE h,
) )
{ {
STHANDLE *sth = (STHANDLE*)h; STHANDLE *sth = (STHANDLE*)h;
if (sth->dwMagic != STMAGIC) return; if (sth->dwMagic != STMAGIC) return 0;
try
{
sth->pst->putSamples(samples, numSamples); sth->pst->putSamples(samples, numSamples);
} }
catch (const std::exception&)
{
return 0;
}
return 1;
}
/// int16 version of soundtouch_putSamples(): This accept int16 (short) sample data /// int16 version of soundtouch_putSamples(): This accept int16 (short) sample data
/// and internally converts it to float format before processing /// and internally converts it to float format before processing
@ -444,7 +476,14 @@ SOUNDTOUCHDLL_API HANDLE __cdecl bpm_createInstance(int numChannels, int sampleR
if (tmp) if (tmp)
{ {
tmp->dwMagic = BPMMAGIC; tmp->dwMagic = BPMMAGIC;
try
{
tmp->pbpm = new BPMDetect(numChannels, sampleRate); tmp->pbpm = new BPMDetect(numChannels, sampleRate);
}
catch (const std::exception&)
{
tmp->pbpm = NULL;
}
if (tmp->pbpm == NULL) if (tmp->pbpm == NULL)
{ {
delete tmp; delete tmp;

View File

@ -112,10 +112,10 @@ SOUNDTOUCHDLL_API void __cdecl soundtouch_setPitchSemiTones(HANDLE h, float newP
/// Sets the number of channels, 1 = mono, 2 = stereo, n = multichannel /// Sets the number of channels, 1 = mono, 2 = stereo, n = multichannel
SOUNDTOUCHDLL_API void __cdecl soundtouch_setChannels(HANDLE h, unsigned int numChannels); SOUNDTOUCHDLL_API int __cdecl soundtouch_setChannels(HANDLE h, unsigned int numChannels);
/// Sets sample rate. /// Sets sample rate.
SOUNDTOUCHDLL_API void __cdecl soundtouch_setSampleRate(HANDLE h, unsigned int srate); SOUNDTOUCHDLL_API int __cdecl soundtouch_setSampleRate(HANDLE h, unsigned int srate);
/// Flushes the last samples from the processing pipeline to the output. /// Flushes the last samples from the processing pipeline to the output.
/// Clears also the internal processing buffers. /// Clears also the internal processing buffers.
@ -124,12 +124,12 @@ SOUNDTOUCHDLL_API void __cdecl soundtouch_setSampleRate(HANDLE h, unsigned int s
/// stream. This function may introduce additional blank samples in the end /// stream. This function may introduce additional blank samples in the end
/// of the sound stream, and thus it's not recommended to call this function /// of the sound stream, and thus it's not recommended to call this function
/// in the middle of a sound stream. /// in the middle of a sound stream.
SOUNDTOUCHDLL_API void __cdecl soundtouch_flush(HANDLE h); SOUNDTOUCHDLL_API int __cdecl soundtouch_flush(HANDLE h);
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into /// Adds 'numSamples' pcs of samples from the 'samples' memory position into
/// the input of the object. Notice that sample rate _has_to_ be set before /// the input of the object. Notice that sample rate _has_to_ be set before
/// calling this function, otherwise throws a runtime_error exception. /// calling this function, otherwise throws a runtime_error exception.
SOUNDTOUCHDLL_API void __cdecl soundtouch_putSamples(HANDLE h, SOUNDTOUCHDLL_API int __cdecl soundtouch_putSamples(HANDLE h,
const float *samples, ///< Pointer to sample buffer. const float *samples, ///< Pointer to sample buffer.
unsigned int numSamples ///< Number of sample frames in buffer. Notice unsigned int numSamples ///< Number of sample frames in buffer. Notice
///< that in case of multi-channel sound a single ///< that in case of multi-channel sound a single