Open benbiles opened 1 year ago
there seams there's only support for one teensy audio channel in AudioOutputOpusEnc::update and AudioInputOpusDec::update
not sure what calls this function yet , new to teensy , I'm thinking I need to add channel support using receiveReadOnly(0); and receiveReadOnly(1);
`
void AudioOutputOpusEnc::update(void) { audio_block_t *block;
audio_block_t *block2; // we need a 2nd block to recieve 2nd channel
block = receiveReadOnly(0); // pointer to audio chaanel 0
block2 = receiveReadOnly(1); // pointer to audio channel 1 ?
// opus encode audio channel 0
if (block) {
if(encoderInitialised)
{
memcpy(encoder_frame_buf_uncompressed, block->data, CONFIG_AUDIO_FRAME_SIZE_SAMPLES * sizeof(int16_t));
encoder_compressed_frame_size = opus_encode(m_opus_encoder_state, encoder_frame_buf_uncompressed, CONFIG_AUDIO_FRAME_SIZE_SAMPLES, encoder_frame_buf_compressed, sizeof(encoder_frame_buf_compressed));
//Serial.printf(" %d", encoder_compressed_frame_size chaanel 0);
}
release(block);
}
// opus encode audio channel 1
if (block2) {
if(encoderInitialised)
{
memcpy(encoder_frame_buf_uncompressed, block2->data, CONFIG_AUDIO_FRAME_SIZE_SAMPLES * sizeof(int16_t));
encoder_compressed_frame_size = opus_encode(m_opus_encoder_state, encoder_frame_buf_uncompressed, CONFIG_AUDIO_FRAME_SIZE_SAMPLES, encoder_frame_buf_compressed, sizeof(encoder_frame_buf_compressed));
//Serial.printf(" %d", encoder_compressed_frame_size channel 1);
}
release(block2);
}
`
Hi , is there a way to enable stereo from line input ?
1st I tried this , but I still get mono.. \ AudioConnection patchCord1(i2s_in, 0, opusEncoder, 0); AudioConnection patchCord2(i2s_in, 1, opusEncoder, 1); AudioConnection patchCord3(opusDecoder, 0, i2s_out, 0); AudioConnection patchCord4(opusDecoder, 1, i2s_out, 1);
Then I tried 2 encoders but get helicopter glitches..
here's my attempt , I'm sure its much more simple than this ? I just doubled up the encoders decoders and made the copy twice.
// Demo code for Opus Encode/Decode for Teensy 4.0
include
include
include
if AUDIO_BLOCK_SAMPLES != 960
error Please define AUDIO_BLOCK_SAMPLES 960 and AUDIO_SAMPLE_RATE_EXACT 48000.0f (in AudioStream.h)
endif
include
include
AudioControlSGTL5000 sgtl5000_1;
AudioInputI2S i2s_in; AudioOutputI2S i2s_out;
AudioOutputOpusEnc opusEncoder; // Create Opus Encoder AudioInputOpusDec opusDecoder; // Create Opus Decoder
AudioOutputOpusEnc opusEncoder2; // Create Opus Encoder AudioInputOpusDec opusDecoder2; // Create Opus Decoder
AudioConnection patchCord1(i2s_in, 0, opusEncoder, 0); AudioConnection patchCord2(i2s_in, 1, opusEncoder2, 0);
AudioConnection patchCord3(opusDecoder, 0, i2s_out, 0); AudioConnection patchCord4(opusDecoder2, 0, i2s_out, 1);
void setup() {
AudioMemory(10); sgtl5000_1.enable();
sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN); sgtl5000_1.volume(0.8);
opusEncoder.initialise(); opusEncoder.setBitrate(64000); // Default is 64000 opusDecoder.initialise();
opusEncoder2.initialise(); opusEncoder2.setBitrate(64000); // Default is 64000 opusDecoder2.initialise();
}
void loop() {
// copy encoder LEFT channel to decoder
uint8_t *opusBuffer; int32_t opusBufSize;
opusBufSize = opusEncoder.hasData(); // Wait for a full block of Opus data
if(opusBufSize > 0) { opusBuffer = opusEncoder.getData(); // Write the encoded data to the buffer opusDecoder.putData(opusBuffer, opusBufSize); // Write the buffer to the decoder (loopback) }
// copy encoder RIGHT channel to decoder
uint8_t *opusBuffer2; int32_t opusBufSize2;
opusBufSize2 = opusEncoder2.hasData(); // Wait for a full block of Opus data
if(opusBufSize2 > 0) { opusBuffer2 = opusEncoder2.getData(); // Write the encoded data to the buffer opusDecoder2.putData(opusBuffer2, opusBufSize2); // Write the buffer to the decoder (loopback) }
} //END loop func