Skip to content

Commit

Permalink
Silence sound while VM is paused.
Browse files Browse the repository at this point in the history
  • Loading branch information
captainys committed Jan 13, 2023
1 parent 1dd7a7f commit 7dd652d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/towns/sound/sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,27 @@ void TownsSound::ProcessSound(void)
}
}

void TownsSound::ProcessSilence(void)
{
std::vector <unsigned char> silence;
if(true!=outside_world->FMPCMChannelPlaying())
{
const unsigned int WAVE_OUT_SAMPLING_RATE=YM2612::WAVE_SAMPLING_RATE; // Align with YM2612.
const uint32_t numSamplesPerWave=FM_PCM_MILLISEC_PER_WAVE*WAVE_OUT_SAMPLING_RATE/1000;
silence.resize(numSamplesPerWave*4);
memset(silence.data(),0,silence.size());
outside_world->FMPCMPlay(silence);
}
if (!outside_world->BeepChannelPlaying())
{
auto BUZZER_SAMPLING_RATE=townsPtr->timer.BUZZER_SAMPLING_RATE();
size_t samples = BUZZER_SAMPLING_RATE * 200; // 5 ms
silence.resize(samples*4);
memset(silence.data(),0,silence.size());
outside_world->BeepPlay(BUZZER_SAMPLING_RATE,silence);
}
}

void TownsSound::StartRecording(void)
{
recordFMandPCM=true;
Expand Down
4 changes: 4 additions & 0 deletions src/towns/sound/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class TownsSound : public Device
*/
void ProcessSound(void);

/*! Call this function periodically while VM is paused.
*/
void ProcessSilence(void);

void StartRecording(void);
void EndRecording(void);
void SaveRecording(std::string fName) const;
Expand Down
1 change: 1 addition & 0 deletions src/towns/townsthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void TownsThread::VMMainLoop(FMTowns *townsPtr,Outside_World *outside_world,clas
runMode=RUNMODE_RUN;
townsPtr->debugger.stop=false;
}
townsPtr->sound.ProcessSilence();
break;
case RUNMODE_RUN:
clockTicking=true;
Expand Down

0 comments on commit 7dd652d

Please sign in to comment.