From 8a51b286515361416cc8a407f37c41cf672a6955 Mon Sep 17 00:00:00 2001 From: Christopher Mosher Date: Mon, 23 Apr 2012 22:55:28 -0400 Subject: [PATCH] for audio, use returned value for silence, and use unsigned instead of signed bytes --- src/speakerclicker.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/speakerclicker.cpp b/src/speakerclicker.cpp index 25296ad..997be80 100644 --- a/src/speakerclicker.cpp +++ b/src/speakerclicker.cpp @@ -25,6 +25,7 @@ std::deque locbuf; volatile bool done; SDL_cond* bufchg; SDL_mutex* buflck; +volatile int silence; // TODO figure out why sound is so choppy, and fix it void fillbuf(void *userdata, Uint8 *stream, int len) @@ -70,7 +71,6 @@ void fillbuf(void *userdata, Uint8 *stream, int len) } #define TICKS_PER_SAMPLE 47 -#define AMP 126 SpeakerClicker::SpeakerClicker(): clicked(false), @@ -80,7 +80,7 @@ SpeakerClicker::SpeakerClicker(): SDL_AudioSpec audio; audio.freq = 22050; // samples per second - audio.format = AUDIO_S8; // 8 bits (1 byte) per sample + audio.format = AUDIO_U8; // 8 bits (1 byte) per sample audio.channels = 1; // mono audio.silence = 0; audio.samples = 4096; @@ -98,15 +98,16 @@ SpeakerClicker::SpeakerClicker(): { bufchg = SDL_CreateCond(); buflck = SDL_CreateMutex(); - /* + silence = obtained.silence; +/* std::cout << "initialized audio: " << std::endl; std::cout << "freq: " << obtained.freq << std::endl; - std::cout << "format: " << (obtained.format==AUDIO_S8?"8-bit":"other") << std::endl; + std::cout << "format: " << obtained.format << std::endl; std::cout << "channels: " << (int)obtained.channels << std::endl; std::cout << "silence: " << (int)obtained.silence << std::endl; std::cout << "samples: " << obtained.samples << std::endl; std::cout << "size: " << obtained.size << std::endl; - */ +*/ SDL_PauseAudio(0); } } @@ -141,13 +142,13 @@ void SpeakerClicker::tick() int amp; if (this->clicked) { - amp = this->positive ? AMP : -AMP; + amp = this->positive ? silence+100 : silence-100; this->positive = !this->positive; this->clicked = false; } else { - amp = 0; + amp = silence; } SDL_LockMutex(buflck); locbuf.push_back(amp);