Skip to content

Commit

Permalink
Merge pull request 'Fix exception throwing across DLL boundary' (RPCS3#2
Browse files Browse the repository at this point in the history
) from sagamusix/soundtouch:master into master

Reviewed-on: https://codeberg.org/soundtouch/soundtouch/pulls/2
  • Loading branch information
Olli Parviainen committed Jan 23, 2022
2 parents 64760eb + 1a07a64 commit 9f14bd8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ source/SoundTouchDll/Win32/
source/SoundTouchDll/x64/
source/SoundTouchDll/DllTest/Win32/
source/SoundTouchDll/DllTest/x64/
.vs

# Files generated by Android Studio
source/android-lib/.gradle
Expand Down
65 changes: 52 additions & 13 deletions source/SoundTouchDLL/SoundTouchDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,37 @@ SOUNDTOUCHDLL_API void __cdecl soundtouch_setPitchSemiTones(HANDLE h, float newP


/// 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;
if (sth->dwMagic != STMAGIC) return;
if (sth->dwMagic != STMAGIC) return 0;

sth->pst->setChannels(numChannels);
try
{
sth->pst->setChannels(numChannels);
}
catch (const std::exception&)
{
return 0;
}
return 1;
}

/// 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;
if (sth->dwMagic != STMAGIC) return;
if (sth->dwMagic != STMAGIC) return 0;

sth->pst->setSampleRate(srate);
try
{
sth->pst->setSampleRate(srate);
}
catch (const std::exception&)
{
return 0;
}
return 1;
}

/// Flushes the last samples from the processing pipeline to the output.
Expand All @@ -231,28 +247,44 @@ SOUNDTOUCHDLL_API void __cdecl soundtouch_setSampleRate(HANDLE h, uint srate)
/// 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
/// 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;
if (sth->dwMagic != STMAGIC) return;
if (sth->dwMagic != STMAGIC) return 0;

sth->pst->flush();
try
{
sth->pst->flush();
}
catch (const std::exception&)
{
return 0;
}
return 1;
}

/// 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
/// 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.
unsigned int numSamples ///< Number of samples in buffer. Notice
///< that in case of stereo-sound a single sample
///< contains data for both channels.
)
{
STHANDLE *sth = (STHANDLE*)h;
if (sth->dwMagic != STMAGIC) return;
if (sth->dwMagic != STMAGIC) return 0;

sth->pst->putSamples(samples, numSamples);
try
{
sth->pst->putSamples(samples, numSamples);
}
catch (const std::exception&)
{
return 0;
}
return 1;
}

/// int16 version of soundtouch_putSamples(): This accept int16 (short) sample data
Expand Down Expand Up @@ -444,7 +476,14 @@ SOUNDTOUCHDLL_API HANDLE __cdecl bpm_createInstance(int numChannels, int sampleR
if (tmp)
{
tmp->dwMagic = BPMMAGIC;
tmp->pbpm = new BPMDetect(numChannels, sampleRate);
try
{
tmp->pbpm = new BPMDetect(numChannels, sampleRate);
}
catch (const std::exception&)
{
tmp->pbpm = NULL;
}
if (tmp->pbpm == NULL)
{
delete tmp;
Expand Down
8 changes: 4 additions & 4 deletions source/SoundTouchDLL/SoundTouchDLL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.
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.
/// Clears also the internal processing buffers.
Expand All @@ -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
/// of the sound stream, and thus it's not recommended to call this function
/// 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
/// the input of the object. Notice that sample rate _has_to_ be set before
/// 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.
unsigned int numSamples ///< Number of sample frames in buffer. Notice
///< that in case of multi-channel sound a single
Expand Down

0 comments on commit 9f14bd8

Please sign in to comment.