100 fprintf(stderr,
"CACodecInputStream fillNativeBuffer\n");
105 UInt32 ioOutputDataPacketSize;
107 AudioBufferList outOutputData;
108 jobject byteBuffer = NULL;
112 byteBuffer = env->GetObjectField(stream, nativeBufferFID);
113 if (byteBuffer == NULL) {
119 acio->
srcBuffer = (
char *)env->GetDirectBufferAddress(byteBuffer);
120 acio->
srcBufferSize = env->GetDirectBufferCapacity(byteBuffer);
126 outOutputData.mNumberBuffers = 1;
127 outOutputData.mBuffers[0].mNumberChannels = acio->
srcFormat.mChannelsPerFrame;
128 outOutputData.mBuffers[0].mDataByteSize = acio->
srcBufferSize;
129 outOutputData.mBuffers[0].mData = acio->
srcBuffer;
131 res = AudioConverterFillComplexBuffer(acio->
acref,
132 CACodecInputStream_ComplexInputDataProc,
134 &ioOutputDataPacketSize,
146 acio->
pos += ioOutputDataPacketSize;
147 if (acio->
srcFormat.mBytesPerPacket != 0) {
148 limit = ioOutputDataPacketSize*acio->
srcFormat.mBytesPerPacket;
152 for (i=0; i<ioOutputDataPacketSize; i++) {
153 limit += acio->
pktDescs[i].mDataByteSize;
157 env->CallObjectMethod(byteBuffer, limitMID, (jint)limit);
158 env->CallObjectMethod(byteBuffer, rewindMID);
162 fprintf(stderr,
"acio->srcFormat.mBytesPerFrame : %i\n", acio->
srcFormat.mBytesPerFrame);
187 jobject byteBuffer = NULL;
188 jclass audioFormatClass = NULL;
189 jmethodID sampleRateMID = NULL;
190 jmethodID channelsMID = NULL;
191 jmethodID frameSizeMID = NULL;
192 jmethodID sampleSizeInBitsMID = NULL;
193 jmethodID encodingMID = NULL;
194 jmethodID bigEndianMID = NULL;
196 jclass caEncodingClass = NULL;
197 jmethodID dataFormatMID = NULL;
198 jobject targetEncoding = NULL;
201 if (fillNativeBufferMID == NULL || hasRemainingMID == NULL || positionMID == NULL || nativeBufferFID == NULL || rewindMID == NULL || limitMID == NULL) {
202 jclass nativePeerInputStreamClass = env->FindClass(
"com/tagtraum/casampledsp/CANativePeerInputStream");
203 fillNativeBufferMID = env->GetMethodID(nativePeerInputStreamClass,
"fillNativeBuffer",
"()V");
204 nativeBufferFID = env->GetFieldID(nativePeerInputStreamClass,
"nativeBuffer",
"Ljava/nio/ByteBuffer;");
205 jclass bufferClass = env->FindClass(
"java/nio/Buffer");
206 hasRemainingMID = env->GetMethodID(bufferClass,
"hasRemaining",
"()Z");
207 positionMID = env->GetMethodID(bufferClass,
"position",
"(I)Ljava/nio/Buffer;");
208 rewindMID = env->GetMethodID(bufferClass,
"rewind",
"()Ljava/nio/Buffer;");
209 limitMID = env->GetMethodID(bufferClass,
"limit",
"(I)Ljava/nio/Buffer;");
213 byteBuffer = env->GetObjectField(stream, nativeBufferFID);
214 if (byteBuffer == NULL) {
223 acio->
srcBuffer = (
char *)env->GetDirectBufferAddress(byteBuffer);
224 acio->
srcBufferSize = env->GetDirectBufferCapacity(byteBuffer);
232 audioFormatClass = env->FindClass(
"javax/sound/sampled/AudioFormat");
233 sampleRateMID = env->GetMethodID(audioFormatClass,
"getSampleRate",
"()F");
234 channelsMID = env->GetMethodID(audioFormatClass,
"getChannels",
"()I");
235 frameSizeMID = env->GetMethodID(audioFormatClass,
"getFrameSize",
"()I");
236 sampleSizeInBitsMID = env->GetMethodID(audioFormatClass,
"getSampleSizeInBits",
"()I");
237 encodingMID = env->GetMethodID(audioFormatClass,
"getEncoding",
"()Ljavax/sound/sampled/AudioFormat$Encoding;");
238 bigEndianMID = env->GetMethodID(audioFormatClass,
"isBigEndian",
"()Z");
240 caEncodingClass = env->FindClass(
"com/tagtraum/casampledsp/CAAudioFormat$CAEncoding");
241 dataFormatMID = env->GetMethodID(caEncodingClass,
"getDataFormat",
"()I");
242 targetEncoding = env->CallObjectMethod(targetFormat, encodingMID);
246 acio->
srcFormat.mSampleRate = (Float64)env->CallFloatMethod(targetFormat, sampleRateMID);
247 acio->
srcFormat.mChannelsPerFrame = (UInt32)env->CallIntMethod(targetFormat, channelsMID);
248 acio->
srcFormat.mBitsPerChannel = (UInt32)env->CallIntMethod(targetFormat, sampleSizeInBitsMID);
250 acio->
srcFormat.mBytesPerFrame = (UInt32)env->CallIntMethod(targetFormat, frameSizeMID);
252 acio->
srcFormat.mFormatID = (UInt32)env->CallIntMethod(targetEncoding, dataFormatMID);
257 if (acio->
srcFormat.mFormatID == kAudioFormatLinearPCM) {
258 acio->
srcFormat.mFormatFlags += env->CallBooleanMethod(targetFormat, bigEndianMID) == JNI_TRUE ? kAudioFormatFlagIsBigEndian : 0;
259 acio->
srcFormat.mFormatFlags += kAudioFormatFlagIsPacked;
262 acio->
srcFormat.mFormatFlags += kAudioFormatFlagIsSignedInteger;
274 if (acio->
srcFormat.mBytesPerFrame == 0) {
278 if (acio->
srcFormat.mBytesPerPacket == 0) {
282 if (acio->
srcFormat.mBitsPerChannel == 0) {
291 env->CallVoidMethod(sourceStream, fillNativeBufferMID);
292 res = acio->
env->ExceptionCheck();
343 if (acio->
acref != NULL) {
344 AudioConverterDispose(acio->
acref);