Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit 81c621f

Browse files
author
StevenLee
committed
Bug 944615 - making AudioHardwareGeneric supports other than 8k frequency. r=vyang
1 parent e3fd3be commit 81c621f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

audio/AudioHardwareGeneric.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,30 @@ status_t AudioHardwareGeneric::dump(int fd, const Vector<String16>& args)
185185
return NO_ERROR;
186186
}
187187

188+
size_t AudioHardwareGeneric::getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
189+
{
190+
if (format != AudioSystem::PCM_16_BIT) {
191+
LOGW("getInputBufferSize supports only PCM_16_BIT, input %d", format);
192+
return 0;
193+
}
194+
if (channelCount != 1) {
195+
LOGW("getInputBufferSize supports channel count 1, input %d", channelCount);
196+
return 0;
197+
}
198+
199+
uint32_t bytesPerSample = audio_bytes_per_sample(format);
200+
uint32_t samplesPerChannel = 0;
201+
202+
if (sampleRate == 8000 || sampleRate == 16000) {
203+
samplesPerChannel = sampleRate / 50;
204+
} else if (sampleRate >= 44100) {
205+
samplesPerChannel = 512;
206+
} else {
207+
samplesPerChannel = 256;
208+
}
209+
210+
return samplesPerChannel * channelCount * bytesPerSample;
211+
}
188212
// ----------------------------------------------------------------------------
189213

190214
status_t AudioStreamOutGeneric::set(

audio/AudioHardwareGeneric.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class AudioHardwareGeneric : public AudioHardwareBase
134134
virtual void closeInputStream(AudioStreamIn* in);
135135

136136
void closeOutputStream(AudioStreamOutGeneric* out);
137+
virtual size_t getInputBufferSize(uint32_t sampleRate, int format, int channelCount);
137138
void closeInputStream(AudioStreamInGeneric* in);
138139
protected:
139140
virtual status_t dump(int fd, const Vector<String16>& args);

0 commit comments

Comments
 (0)