From c8fcce1de3041a6d192ebac6e724656ba273ac36 Mon Sep 17 00:00:00 2001 From: Tobi Date: Tue, 23 Nov 2021 16:39:20 +0100 Subject: [PATCH] Update sound.cpp --- sound.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sound.cpp b/sound.cpp index d8d7faa..fef3d58 100644 --- a/sound.cpp +++ b/sound.cpp @@ -5,6 +5,7 @@ #include #include +extern bool isndspinit; using std::string; // Reference: http://yannesposito.com/Scratch/en/blog/2010-10-14-Fun-with-wav/ @@ -25,6 +26,7 @@ typedef struct _WavHeader { static_assert(sizeof(WavHeader) == 44, "WavHeader size is not 44 bytes."); sound::sound(const string& path, int channel, bool toloop) { + if (isndspinit){ ndspSetOutputMode(NDSP_OUTPUT_STEREO); ndspSetOutputCount(2); // Num of buffers @@ -98,10 +100,11 @@ sound::sound(const string& path, int channel, bool toloop) { waveBuf.nsamples = dataSize / (wavHeader.bits_per_sample >> 3); waveBuf.looping = toloop; waveBuf.status = NDSP_WBUF_FREE; - chnl = channel; + chnl = channel;} } sound::~sound() { + if (isndspinit){ waveBuf.data_vaddr = 0; waveBuf.nsamples = 0; waveBuf.looping = false; @@ -110,16 +113,18 @@ sound::~sound() { if (data) { linearFree(data); - } + }} } void sound::play() { + if (isndspinit){ if (!data) return; DSP_FlushDataCache(data, dataSize); - ndspChnWaveBufAdd(chnl, &waveBuf); + ndspChnWaveBufAdd(chnl, &waveBuf);} } void sound::stop() { + if (isndspinit){ if (!data) return; - ndspChnWaveBufClear(chnl); -} \ No newline at end of file + ndspChnWaveBufClear(chnl);} +}