OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 #include "config.h" | 29 #include "config.h" |
30 | 30 |
31 #if ENABLE(WEB_AUDIO) | 31 #if ENABLE(WEB_AUDIO) |
32 | 32 |
33 #include "core/platform/audio/AudioFIFO.h" | 33 #include "core/platform/audio/AudioFIFO.h" |
34 | 34 |
35 namespace WebCore { | 35 namespace WebCore { |
36 | 36 |
37 AudioFIFO::AudioFIFO(unsigned numberOfChannels, size_t fifoLength) | 37 AudioFIFO::AudioFIFO(unsigned numberOfChannels, size_t fifoLength) |
38 : m_fifoAudioBus(numberOfChannels, fifoLength) | 38 : m_fifoAudioBus(AudioBus::create(numberOfChannels, fifoLength)) |
39 , m_fifoLength(fifoLength) | 39 , m_fifoLength(fifoLength) |
40 , m_framesInFifo(0) | 40 , m_framesInFifo(0) |
41 , m_readIndex(0) | 41 , m_readIndex(0) |
42 , m_writeIndex(0) | 42 , m_writeIndex(0) |
43 { | 43 { |
44 } | 44 } |
45 | 45 |
46 void AudioFIFO::consume(AudioBus* destination, size_t framesToConsume) | 46 void AudioFIFO::consume(AudioBus* destination, size_t framesToConsume) |
47 { | 47 { |
48 bool isGood = destination && (framesToConsume <= m_fifoLength) && (framesToC
onsume <= m_framesInFifo) && (destination->length() >= framesToConsume); | 48 bool isGood = destination && (framesToConsume <= m_fifoLength) && (framesToC
onsume <= m_framesInFifo) && (destination->length() >= framesToConsume); |
49 ASSERT(isGood); | 49 ASSERT(isGood); |
50 if (!isGood) | 50 if (!isGood) |
51 return; | 51 return; |
52 | 52 |
53 // Copy the requested number of samples to the destination. | 53 // Copy the requested number of samples to the destination. |
54 | 54 |
55 size_t part1Length; | 55 size_t part1Length; |
56 size_t part2Length; | 56 size_t part2Length; |
57 findWrapLengths(m_readIndex, framesToConsume, part1Length, part2Length); | 57 findWrapLengths(m_readIndex, framesToConsume, part1Length, part2Length); |
58 | 58 |
59 size_t numberOfChannels = m_fifoAudioBus.numberOfChannels(); | 59 size_t numberOfChannels = m_fifoAudioBus->numberOfChannels(); |
60 | 60 |
61 for (size_t channelIndex = 0; channelIndex < numberOfChannels; ++channelInde
x) { | 61 for (size_t channelIndex = 0; channelIndex < numberOfChannels; ++channelInde
x) { |
62 float* destinationData = destination->channel(channelIndex)->mutableData
(); | 62 float* destinationData = destination->channel(channelIndex)->mutableData
(); |
63 const float* sourceData = m_fifoAudioBus.channel(channelIndex)->data(); | 63 const float* sourceData = m_fifoAudioBus->channel(channelIndex)->data(); |
64 | 64 |
65 bool isCopyGood = ((m_readIndex < m_fifoLength) | 65 bool isCopyGood = ((m_readIndex < m_fifoLength) |
66 && (m_readIndex + part1Length) <= m_fifoLength | 66 && (m_readIndex + part1Length) <= m_fifoLength |
67 && (part1Length <= destination->length()) | 67 && (part1Length <= destination->length()) |
68 && (part1Length + part2Length) <= destination->length
()); | 68 && (part1Length + part2Length) <= destination->length
()); |
69 ASSERT(isCopyGood); | 69 ASSERT(isCopyGood); |
70 if (!isCopyGood) | 70 if (!isCopyGood) |
71 return; | 71 return; |
72 | 72 |
73 memcpy(destinationData, sourceData + m_readIndex, part1Length * sizeof(*
sourceData)); | 73 memcpy(destinationData, sourceData + m_readIndex, part1Length * sizeof(*
sourceData)); |
(...skipping 12 matching lines...) Expand all Loading... |
86 | 86 |
87 bool isGood = sourceBus && (m_framesInFifo + sourceBus->length() <= m_fifoLe
ngth); | 87 bool isGood = sourceBus && (m_framesInFifo + sourceBus->length() <= m_fifoLe
ngth); |
88 if (!isGood) | 88 if (!isGood) |
89 return; | 89 return; |
90 | 90 |
91 size_t sourceLength = sourceBus->length(); | 91 size_t sourceLength = sourceBus->length(); |
92 size_t part1Length; | 92 size_t part1Length; |
93 size_t part2Length; | 93 size_t part2Length; |
94 findWrapLengths(m_writeIndex, sourceLength, part1Length, part2Length); | 94 findWrapLengths(m_writeIndex, sourceLength, part1Length, part2Length); |
95 | 95 |
96 size_t numberOfChannels = m_fifoAudioBus.numberOfChannels(); | 96 size_t numberOfChannels = m_fifoAudioBus->numberOfChannels(); |
97 | 97 |
98 for (size_t channelIndex = 0; channelIndex < numberOfChannels; ++channelInde
x) { | 98 for (size_t channelIndex = 0; channelIndex < numberOfChannels; ++channelInde
x) { |
99 float* destination = m_fifoAudioBus.channel(channelIndex)->mutableData()
; | 99 float* destination = m_fifoAudioBus->channel(channelIndex)->mutableData(
); |
100 const float* source = sourceBus->channel(channelIndex)->data(); | 100 const float* source = sourceBus->channel(channelIndex)->data(); |
101 | 101 |
102 bool isCopyGood = ((m_writeIndex < m_fifoLength) | 102 bool isCopyGood = ((m_writeIndex < m_fifoLength) |
103 && (m_writeIndex + part1Length) <= m_fifoLength | 103 && (m_writeIndex + part1Length) <= m_fifoLength |
104 && part2Length < m_fifoLength | 104 && part2Length < m_fifoLength |
105 && part1Length + part2Length <= sourceLength); | 105 && part1Length + part2Length <= sourceLength); |
106 ASSERT(isCopyGood); | 106 ASSERT(isCopyGood); |
107 if (!isCopyGood) | 107 if (!isCopyGood) |
108 return; | 108 return; |
109 | 109 |
(...skipping 25 matching lines...) Expand all Loading... |
135 } else { | 135 } else { |
136 // Invalid values for index or size. Set the part lengths to zero so not
hing is copied. | 136 // Invalid values for index or size. Set the part lengths to zero so not
hing is copied. |
137 part1Length = 0; | 137 part1Length = 0; |
138 part2Length = 0; | 138 part2Length = 0; |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 } // namespace WebCore | 142 } // namespace WebCore |
143 | 143 |
144 #endif // ENABLE(WEB_AUDIO) | 144 #endif // ENABLE(WEB_AUDIO) |
OLD | NEW |