Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 30 of 30

Thread: Audio Sample Rate: how to change from 44100 Hz (44117.65 Hz) to 48000?

  1. #26
    Senior Member MickMad's Avatar
    Join Date
    Feb 2013
    Location
    Essonne, France
    Posts
    149
    Quote Originally Posted by roomtek View Post
    Yes. In fact after I get the callback, I set the new MCLK and set the new sample rate to my I2S Ics and the audio resumes on the PC:

    Code:
    
    void audioformat_change() // change sample rate requests
    {
      Serial.println("audioformat_change_callback");
    
      dac.muteAudio(1, 1);
      RADIOMODES mode = radio.mode;
      Serial.printf("New samplerate: %d\n", usb_audio_sampling_frequency);
      recorder.halt(); // stop everything here
      setupI2SCLOCKS(usb_audio_sampling_frequency);
      radio.audio_sample_rate = usb_audio_sampling_frequency;
      radio.prop(P_DIGITAL_IO_OUTPUT_SAMPLE_RATE, usb_audio_sampling_frequency);
      //  if (mode != RADIO_OFF)
      //    radio.powerUp();
      dac.muteAudio(0, 0);
      audio_rate_change = false;
    }
    mh, I'm trying a simple sketch where I connected an AudioSynthWaveformSine object to both USB audio outputs but all I get is empty packets.

    Anyway, I'll try it with I2S objects too and see if it works.

  2. #27
    Senior Member
    Join Date
    Oct 2016
    Posts
    162
    I'm confused, what i need to do for 48khz USB?

    I can't understand which files change, i need only one sample rate from USB (48 khz), for now my project works fine at 48 khz i2s with setI2SFreq but if i want to try with usb input i have a pitched down audio..

    Thank you

    Dani

  3. #28
    basically the teensy needs to tell the PC that it has a larger packet size to send.

    These were my modifications:

    In usb_audio.cpp:
    Code:
    unsigned int usb_audio_transmit_callback(void)
    {
    	uint32_t avail, num, target = 48, offset, len=0;
    	audio_block_t *left, *right;  
    
    	while (len < target) { // fill the buffer
    		num = target - len;
    		left = AudioOutputUSB::left_1st;
    		if (left == NULL) {
    			// buffer underrun - PC is consuming too quickly
    			memset(usb_audio_transmit_buffer + len, 0, num * 4); 
    			break;
    		}
    		right = AudioOutputUSB::right_1st;
    		offset = AudioOutputUSB::offset_1st;
    
    		avail = AUDIO_BLOCK_SAMPLES - offset;
    		if (num > avail) num = avail;
    
    		copy_from_buffers((uint32_t *)usb_audio_transmit_buffer + len,
    			left->data + offset, right->data + offset, num);
    		len += num;
    		offset += num;
    		if (offset >= AUDIO_BLOCK_SAMPLES) {
    			AudioStream::release(left);
    			AudioStream::release(right);
    			AudioOutputUSB::left_1st = AudioOutputUSB::left_2nd;
    			AudioOutputUSB::left_2nd = NULL;
    			AudioOutputUSB::right_1st = AudioOutputUSB::right_2nd;
    			AudioOutputUSB::right_2nd = NULL;
    			AudioOutputUSB::offset_1st = 0;
    		} else {
    			AudioOutputUSB::offset_1st = offset;
    		}
    	}
    	return target * 4;
    }
    In usb_desc.h:
    Code:
    #define AUDIO_TX_SIZE         192

    In usb_desc.c:
    Code:
    LSB(48000), MSB(48000), 0,		// tSamFreq

    In usb_dev.c:
    Code:
     case 0x81A2: // GET_CUR (wValue=0, wIndex=interface, wLength=len)
    		if (setup.wLength >= 3) {
    			reply_buffer[0] = 48000 & 255; 
    			reply_buffer[1] = 48000 >> 8; 
    			reply_buffer[2] = 0;
    			datalen = 3;
    			data = reply_buffer;
    		} else {
    			endpoint0_stall();
    			return;
    		}
    		break;

  4. #29
    Senior Member
    Join Date
    Oct 2016
    Posts
    162
    there are are a lot of noises using setI2SFreq(48000); without this it works (i can see 16 bit 48khz on pc) but sometimes there are clicks... so it's far to acceptable

  5. #30
    I do not get any clicks. Clicks happened for me when I was sending the wrong TX size. Without seeing your code, it is hard to tell...
    Last edited by roomtek; 11-07-2017 at 02:19 AM. Reason: typo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •