| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/audio/simple_sources.h" | 5 #include "media/audio/simple_sources.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <math.h> | 8 #include <math.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 int16* sin_tbl = reinterpret_cast<int16*>(dest); | 36 int16* sin_tbl = reinterpret_cast<int16*>(dest); |
| 37 uint32 len = max_size / sizeof(int16); | 37 uint32 len = max_size / sizeof(int16); |
| 38 // The table is filled with s(t) = 32768*sin(2PI*f*t). | 38 // The table is filled with s(t) = 32768*sin(2PI*f*t). |
| 39 for (uint32 ix = 0; ix != len; ++ix) { | 39 for (uint32 ix = 0; ix != len; ++ix) { |
| 40 double th = kTwoPi * ix * f; | 40 double th = kTwoPi * ix * f; |
| 41 sin_tbl[ix] = static_cast<int16>((1 << 15) * sin(th)); | 41 sin_tbl[ix] = static_cast<int16>((1 << 15) * sin(th)); |
| 42 } | 42 } |
| 43 return max_size; | 43 return max_size; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void SineWaveAudioSource::OnClose(AudioOutputStream* stream) { | |
| 47 } | |
| 48 | |
| 49 void SineWaveAudioSource::OnError(AudioOutputStream* stream, int code) { | 46 void SineWaveAudioSource::OnError(AudioOutputStream* stream, int code) { |
| 50 NOTREACHED(); | 47 NOTREACHED(); |
| 51 } | 48 } |
| 52 | 49 |
| 53 ////////////////////////////////////////////////////////////////////////////// | 50 ////////////////////////////////////////////////////////////////////////////// |
| 54 // PushSource implementation. | 51 // PushSource implementation. |
| 55 | 52 |
| 56 PushSource::PushSource() | 53 PushSource::PushSource() |
| 57 : buffer_(0, 0) { | 54 : buffer_(0, 0) { |
| 58 } | 55 } |
| 59 | 56 |
| 60 PushSource::~PushSource() { } | 57 PushSource::~PushSource() { } |
| 61 | 58 |
| 62 uint32 PushSource::OnMoreData( | 59 uint32 PushSource::OnMoreData( |
| 63 AudioOutputStream* stream, uint8* dest, uint32 max_size, | 60 AudioOutputStream* stream, uint8* dest, uint32 max_size, |
| 64 AudioBuffersState buffers_state) { | 61 AudioBuffersState buffers_state) { |
| 65 return buffer_.Read(dest, max_size); | 62 return buffer_.Read(dest, max_size); |
| 66 } | 63 } |
| 67 | 64 |
| 68 void PushSource::OnClose(AudioOutputStream* stream) { | |
| 69 CleanUp(); | |
| 70 } | |
| 71 | |
| 72 void PushSource::OnError(AudioOutputStream* stream, int code) { | 65 void PushSource::OnError(AudioOutputStream* stream, int code) { |
| 73 NOTREACHED(); | 66 NOTREACHED(); |
| 74 } | 67 } |
| 75 | 68 |
| 76 // TODO(cpu): Manage arbitrary large sizes. | 69 // TODO(cpu): Manage arbitrary large sizes. |
| 77 bool PushSource::Write(const void *data, uint32 len) { | 70 bool PushSource::Write(const void *data, uint32 len) { |
| 78 if (len == 0) { | 71 if (len == 0) { |
| 79 NOTREACHED(); | 72 NOTREACHED(); |
| 80 return false; | 73 return false; |
| 81 } | 74 } |
| 82 buffer_.Append(static_cast<const uint8*>(data), len); | 75 buffer_.Append(static_cast<const uint8*>(data), len); |
| 83 return true; | 76 return true; |
| 84 } | 77 } |
| 85 | 78 |
| 86 uint32 PushSource::UnProcessedBytes() { | 79 uint32 PushSource::UnProcessedBytes() { |
| 87 return buffer_.forward_bytes(); | 80 return buffer_.forward_bytes(); |
| 88 } | 81 } |
| 89 | 82 |
| 90 void PushSource::ClearAll() { | 83 void PushSource::ClearAll() { |
| 91 // Cleanup() will discard all the data. | 84 // Cleanup() will discard all the data. |
| 92 CleanUp(); | 85 CleanUp(); |
| 93 } | 86 } |
| 94 | 87 |
| 95 void PushSource::CleanUp() { | 88 void PushSource::CleanUp() { |
| 96 buffer_.Clear(); | 89 buffer_.Clear(); |
| 97 } | 90 } |
| OLD | NEW |