diff options
author | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 22:25:18 +0000 |
---|---|---|
committer | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-04 22:25:18 +0000 |
commit | 3ee84160f356ad78f48639b4e26eebee9a88b9c1 (patch) | |
tree | 41cdcce0762674b9eb5893d0585673d91bea53e2 /media/audio | |
parent | 3da33567fb3c69351d74ccb11d884e4ea9f9a21e (diff) | |
download | chromium_src-3ee84160f356ad78f48639b4e26eebee9a88b9c1.zip chromium_src-3ee84160f356ad78f48639b4e26eebee9a88b9c1.tar.gz chromium_src-3ee84160f356ad78f48639b4e26eebee9a88b9c1.tar.bz2 |
SetVolume and GetVolume take one volume instead of separate left and right volumes.
BUG=26660
TEST=no visible difference. Make sure volume still works. Code size should go down marginally.
Review URL: http://codereview.chromium.org/357004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31018 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r-- | media/audio/audio_output.h | 20 | ||||
-rw-r--r-- | media/audio/fake_audio_output_stream.cc | 13 | ||||
-rw-r--r-- | media/audio/fake_audio_output_stream.h | 11 | ||||
-rw-r--r-- | media/audio/linux/alsa_output.cc | 8 | ||||
-rw-r--r-- | media/audio/linux/alsa_output.h | 4 | ||||
-rw-r--r-- | media/audio/linux/audio_manager_linux.cc | 7 | ||||
-rw-r--r-- | media/audio/mac/audio_output_mac.cc | 13 | ||||
-rw-r--r-- | media/audio/mac/audio_output_mac.h | 4 | ||||
-rw-r--r-- | media/audio/mac/audio_output_mac_unittest.cc | 14 | ||||
-rw-r--r-- | media/audio/win/audio_output_win_unittest.cc | 49 | ||||
-rw-r--r-- | media/audio/win/waveout_output_win.cc | 11 | ||||
-rw-r--r-- | media/audio/win/waveout_output_win.h | 4 |
12 files changed, 71 insertions, 87 deletions
diff --git a/media/audio/audio_output.h b/media/audio/audio_output.h index e6a1ee5..29712bf 100644 --- a/media/audio/audio_output.h +++ b/media/audio/audio_output.h @@ -91,13 +91,11 @@ class AudioOutputStream { // might have locked audio data that is processing. virtual void Stop() = 0; - // Sets the relative volume, with range [0.0, 1.0] inclusive. For mono audio - // sources the volume must be the same in both channels. - virtual void SetVolume(double left_level, double right_level) = 0; + // Sets the relative volume, with range [0.0, 1.0] inclusive. + virtual void SetVolume(double volume) = 0; - // Gets the relative volume, with range [0.0, 1.0] inclusive. For mono audio - // sources the level is returned in both channels. - virtual void GetVolume(double* left_level, double* right_level) = 0; + // Gets the relative volume, with range [0.0, 1.0] inclusive. + virtual void GetVolume(double* volume) = 0; // Close the stream. This also generates AudioSourceCallback::OnClose(). // After calling this method, the object should not be used anymore. @@ -113,11 +111,11 @@ class AudioOutputStream { class AudioManager { public: enum Format { - AUDIO_PCM_LINEAR = 0, // Pulse code modulation means 'raw' amplitude - // samples. - AUDIO_PCM_DELTA, // Delta-encoded pulse code modulation. - AUDIO_MOCK, // Creates a dummy AudioOutputStream object. - AUDIO_LAST_FORMAT // Only used for validation of format. + AUDIO_PCM_LINEAR = 0, // Pulse code modulation means 'raw' amplitude + // samples. + AUDIO_PCM_DELTA, // Delta-encoded pulse code modulation. + AUDIO_MOCK, // Creates a dummy AudioOutputStream object. + AUDIO_LAST_FORMAT // Only used for validation of format. }; // Telephone quality sample rate, mostly for speech-only audio. diff --git a/media/audio/fake_audio_output_stream.cc b/media/audio/fake_audio_output_stream.cc index af69a2f..cd57719 100644 --- a/media/audio/fake_audio_output_stream.cc +++ b/media/audio/fake_audio_output_stream.cc @@ -39,14 +39,12 @@ void FakeAudioOutputStream::Start(AudioSourceCallback* callback) { void FakeAudioOutputStream::Stop() { } -void FakeAudioOutputStream::SetVolume(double left_level, double right_level) { - left_volume_ = left_level; - right_volume_ = right_level; +void FakeAudioOutputStream::SetVolume(double volume) { + volume_ = volume; } -void FakeAudioOutputStream::GetVolume(double* left_level, double* right_level) { - *left_level = left_volume_; - *right_level = right_volume_; +void FakeAudioOutputStream::GetVolume(double* volume) { + *volume = volume_; } void FakeAudioOutputStream::Close() { @@ -59,8 +57,7 @@ void FakeAudioOutputStream::Close() { } FakeAudioOutputStream::FakeAudioOutputStream() - : left_volume_(0), - right_volume_(0), + : volume_(0), callback_(NULL), packet_size_(0) { } diff --git a/media/audio/fake_audio_output_stream.h b/media/audio/fake_audio_output_stream.h index 0cab082..5c7da82 100644 --- a/media/audio/fake_audio_output_stream.h +++ b/media/audio/fake_audio_output_stream.h @@ -22,13 +22,12 @@ class FakeAudioOutputStream : public AudioOutputStream { virtual bool Open(size_t packet_size); virtual void Start(AudioSourceCallback* callback); virtual void Stop(); - virtual void SetVolume(double left_level, double right_level); - virtual void GetVolume(double* left_level, double* right_level); + virtual void SetVolume(double volume); + virtual void GetVolume(double* volume); virtual void Close(); char* buffer() { return buffer_.get(); } - double left_volume() { return left_volume_; } - double right_volume() { return right_volume_; } + double volume() { return volume_; } private: FakeAudioOutputStream(); @@ -38,8 +37,7 @@ class FakeAudioOutputStream : public AudioOutputStream { static bool has_created_fake_stream_; static FakeAudioOutputStream* last_fake_stream_; - double left_volume_; - double right_volume_; + double volume_; AudioSourceCallback* callback_; scoped_array<char> buffer_; size_t packet_size_; @@ -48,3 +46,4 @@ class FakeAudioOutputStream : public AudioOutputStream { }; #endif // MEDIA_AUDIO_FAKE_AUDIO_OUTPUT_STREAM_H_ + diff --git a/media/audio/linux/alsa_output.cc b/media/audio/linux/alsa_output.cc index 51da10d..f6091a8 100644 --- a/media/audio/linux/alsa_output.cc +++ b/media/audio/linux/alsa_output.cc @@ -350,16 +350,16 @@ void AlsaPcmOutputStream::Stop() { shared_data_.TransitionTo(kIsStopped); } -void AlsaPcmOutputStream::SetVolume(double left_level, double right_level) { +void AlsaPcmOutputStream::SetVolume(double volume) { DCHECK_EQ(MessageLoop::current(), client_thread_loop_); - shared_data_.set_volume(static_cast<float>(left_level)); + shared_data_.set_volume(static_cast<float>(volume)); } -void AlsaPcmOutputStream::GetVolume(double* left_level, double* right_level) { +void AlsaPcmOutputStream::GetVolume(double* volume) { DCHECK_EQ(MessageLoop::current(), client_thread_loop_); - *left_level = *right_level = shared_data_.volume(); + *volume = shared_data_.volume(); } void AlsaPcmOutputStream::OpenTask(size_t packet_size) { diff --git a/media/audio/linux/alsa_output.h b/media/audio/linux/alsa_output.h index 5bdaa1b..58d9ea0 100644 --- a/media/audio/linux/alsa_output.h +++ b/media/audio/linux/alsa_output.h @@ -82,8 +82,8 @@ class AlsaPcmOutputStream : virtual void Close(); virtual void Start(AudioSourceCallback* callback); virtual void Stop(); - virtual void SetVolume(double left_level, double right_level); - virtual void GetVolume(double* left_level, double* right_level); + virtual void SetVolume(double volume); + virtual void GetVolume(double* volume); private: friend class AlsaPcmOutputStreamTest; diff --git a/media/audio/linux/audio_manager_linux.cc b/media/audio/linux/audio_manager_linux.cc index 9d395e8..b3d21f5 100644 --- a/media/audio/linux/audio_manager_linux.cc +++ b/media/audio/linux/audio_manager_linux.cc @@ -14,6 +14,7 @@ namespace { + AudioManagerLinux* g_audio_manager = NULL; } // namespace @@ -75,8 +76,10 @@ void AudioManagerLinux::UnMuteAll() { } void AudioManagerLinux::ReleaseStream(AlsaPcmOutputStream* stream) { - AutoLock l(lock_); - active_streams_.erase(stream); + if (stream) { + AutoLock l(lock_); + active_streams_.erase(stream); + } } // TODO(ajwong): Collapse this with the windows version. diff --git a/media/audio/mac/audio_output_mac.cc b/media/audio/mac/audio_output_mac.cc index 42e80a1..24dc86b 100644 --- a/media/audio/mac/audio_output_mac.cc +++ b/media/audio/mac/audio_output_mac.cc @@ -146,25 +146,22 @@ void PCMQueueOutAudioOutputStream::Stop() { HandleError(err); } -void PCMQueueOutAudioOutputStream::SetVolume(double left_level, - double ) { +void PCMQueueOutAudioOutputStream::SetVolume(double volume) { if (!audio_queue_) return; - volume_ = static_cast<float>(left_level); + volume_ = static_cast<float>(volume); OSStatus err = AudioQueueSetParameter(audio_queue_, kAudioQueueParam_Volume, - left_level); + volume); if (err != noErr) { HandleError(err); } } -void PCMQueueOutAudioOutputStream::GetVolume(double* left_level, - double* right_level) { +void PCMQueueOutAudioOutputStream::GetVolume(double* volume) { if (!audio_queue_) return; - *left_level = volume_; - *right_level = volume_; + *volume = volume_; } // Reorder PCM from AAC layout to Core Audio layout. diff --git a/media/audio/mac/audio_output_mac.h b/media/audio/mac/audio_output_mac.h index 14afff7..10fc229 100644 --- a/media/audio/mac/audio_output_mac.h +++ b/media/audio/mac/audio_output_mac.h @@ -33,8 +33,8 @@ class PCMQueueOutAudioOutputStream : public AudioOutputStream { virtual void Close(); virtual void Start(AudioSourceCallback* callback); virtual void Stop(); - virtual void SetVolume(double left_level, double right_level); - virtual void GetVolume(double* left_level, double* right_level); + virtual void SetVolume(double volume); + virtual void GetVolume(double* volume); private: // The audio is double buffered. diff --git a/media/audio/mac/audio_output_mac_unittest.cc b/media/audio/mac/audio_output_mac_unittest.cc index a517e95..985ca45 100644 --- a/media/audio/mac/audio_output_mac_unittest.cc +++ b/media/audio/mac/audio_output_mac_unittest.cc @@ -92,19 +92,15 @@ TEST(MacAudioTest, PCMWaveStreamPlay200HzTone44KssMono) { EXPECT_TRUE(oas->Open(bytes_100_ms)); - oas->SetVolume(0.5, 0.5); + oas->SetVolume(0.5); oas->Start(&source); usleep(1500000); // Test that the volume is within the set limits. - double left_volume = 0.0; - double right_volume = 0.0; - oas->GetVolume(&left_volume, &right_volume); - EXPECT_LT(left_volume, 0.51); - EXPECT_GT(left_volume, 0.49); - EXPECT_LT(right_volume, 0.51); - EXPECT_GT(right_volume, 0.49); - + double volume = 0.0; + oas->GetVolume(&volume); + EXPECT_LT(volume, 0.51); + EXPECT_GT(volume, 0.49); oas->Stop(); oas->Close(); } diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc index 38a32f8..33d016d 100644 --- a/media/audio/win/audio_output_win_unittest.cc +++ b/media/audio/win/audio_output_win_unittest.cc @@ -303,7 +303,7 @@ TEST(WinAudioTest, PCMWaveStreamTripleBuffer) { EXPECT_GT(test_triple_buffer.callback_count(), kNumBuffers); EXPECT_FALSE(test_triple_buffer.had_error()); oas->Stop(); - ::Sleep(1000); + ::Sleep(500); oas->Close(); } @@ -325,11 +325,11 @@ TEST(WinAudioTest, PCMWaveSlowSource) { // The test parameters cause a callback every 32 ms and the source is // sleeping for 90 ms, so it is guaranteed that we run out of ready buffers. oas->Start(&test_laggy); - ::Sleep(1000); + ::Sleep(500); EXPECT_GT(test_laggy.callback_count(), 2); EXPECT_FALSE(test_laggy.had_error()); oas->Stop(); - ::Sleep(1000); + ::Sleep(500); oas->Close(); } @@ -353,9 +353,9 @@ TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; EXPECT_TRUE(oas->Open(bytes_100_ms)); - oas->SetVolume(1.0, 1.0); + oas->SetVolume(1.0); - for (int ix = 0; ix != 25; ++ix) { + for (int ix = 0; ix != 5; ++ix) { oas->Start(&source); ::Sleep(10); oas->Stop(); @@ -364,7 +364,7 @@ TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { } -// This test produces actual audio for 1.5 seconds on the default wave +// This test produces actual audio for .5 seconds on the default wave // device at 44.1K s/sec. Parameters have been chosen carefully so you should // not hear pops or noises while the sound is playing. TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { @@ -384,14 +384,14 @@ TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; EXPECT_TRUE(oas->Open(bytes_100_ms)); - oas->SetVolume(1.0, 1.0); + oas->SetVolume(1.0); oas->Start(&source); - ::Sleep(1500); + ::Sleep(500); oas->Stop(); oas->Close(); } -// This test produces actual audio for for 1.5 seconds on the default wave +// This test produces actual audio for for .5 seconds on the default wave // device at 22K s/sec. Parameters have been chosen carefully so you should // not hear pops or noises while the sound is playing. The audio also should // sound with a lower volume than PCMWaveStreamPlay200HzTone44Kss. @@ -413,18 +413,15 @@ TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { EXPECT_TRUE(oas->Open(bytes_100_ms)); - oas->SetVolume(0.5, 0.5); + oas->SetVolume(0.5); oas->Start(&source); - ::Sleep(1500); + ::Sleep(500); // Test that the volume is within the set limits. - double left_volume = 0.0; - double right_volume = 0.0; - oas->GetVolume(&left_volume, &right_volume); - EXPECT_LT(left_volume, 0.51); - EXPECT_GT(left_volume, 0.49); - EXPECT_LT(right_volume, 0.51); - EXPECT_GT(right_volume, 0.49); + double volume = 0.0; + oas->GetVolume(&volume); + EXPECT_LT(volume, 0.51); + EXPECT_GT(volume, 0.49); oas->Stop(); oas->Close(); } @@ -479,14 +476,14 @@ TEST(WinAudioTest, PushSourceFile16KHz) { } // Play a little bit more of the file. - ::Sleep(4000); + ::Sleep(500); oas->Stop(); oas->Close(); } // This test is to make sure an AudioOutputStream can be started after it was -// stopped. You will here two 1.5 seconds wave signal separated by 0.5 seconds +// stopped. You will here two .5 seconds wave signal separated by 0.5 seconds // of silence. TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { if (IsRunningHeadless()) @@ -505,19 +502,19 @@ TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { size_t bytes_100_ms = (AudioManager::kAudioCDSampleRate / 10) * 2; EXPECT_TRUE(oas->Open(bytes_100_ms)); - oas->SetVolume(1.0, 1.0); + oas->SetVolume(1.0); - // Play the wave for 1.5 seconds. + // Play the wave for .5 seconds. oas->Start(&source); - ::Sleep(1500); + ::Sleep(500); oas->Stop(); // Sleep to give silence after stopping the AudioOutputStream. - ::Sleep(500); + ::Sleep(250); - // Start again and play for 1.5 seconds. + // Start again and play for .5 seconds. oas->Start(&source); - ::Sleep(1500); + ::Sleep(500); oas->Stop(); oas->Close(); diff --git a/media/audio/win/waveout_output_win.cc b/media/audio/win/waveout_output_win.cc index 2411527..0611da1 100644 --- a/media/audio/win/waveout_output_win.cc +++ b/media/audio/win/waveout_output_win.cc @@ -215,19 +215,16 @@ void PCMWaveOutAudioOutputStream::Close() { manager_->ReleaseStream(this); } -void PCMWaveOutAudioOutputStream::SetVolume(double left_level, - double ) { +void PCMWaveOutAudioOutputStream::SetVolume(double volume) { if (!waveout_) return; - volume_ = static_cast<float>(left_level); + volume_ = static_cast<float>(volume); } -void PCMWaveOutAudioOutputStream::GetVolume(double* left_level, - double* right_level) { +void PCMWaveOutAudioOutputStream::GetVolume(double* volume) { if (!waveout_) return; - *left_level = volume_; - *right_level = volume_; + *volume = volume_; } void PCMWaveOutAudioOutputStream::HandleError(MMRESULT error) { diff --git a/media/audio/win/waveout_output_win.h b/media/audio/win/waveout_output_win.h index 4f090ba..d965d9f 100644 --- a/media/audio/win/waveout_output_win.h +++ b/media/audio/win/waveout_output_win.h @@ -38,8 +38,8 @@ class PCMWaveOutAudioOutputStream : public AudioOutputStream { virtual void Close(); virtual void Start(AudioSourceCallback* callback); virtual void Stop(); - virtual void SetVolume(double left_level, double right_level); - virtual void GetVolume(double* left_level, double* right_level); + virtual void SetVolume(double volume); + virtual void GetVolume(double* volume); // Sends a buffer to the audio driver for playback. void QueueNextPacket(WAVEHDR* buffer); |