Example #1
0
//*****************************************************************************
//
//! Starts playback of a song.
//!
//! \param pusSong is a pointer to the song data structure.
//! \param ulLength is the length of the song data structure in bytes.
//!
//! This function starts the playback of a song or sound effect.  If a song
//! or sound effect is already being played, its playback is canceled and the
//! new song is started.
//!
//! \return None.
//
//*****************************************************************************
void
SoundPlay(const unsigned short *pusSong, unsigned long ulLength)
{
    //
    // Set the format of the audio stream.
    //
    SoundSetFormat(48000, 16, 2);

    //
    // Save the music buffer.
    //
    g_ulMusicCount = 0;
    g_ulMusicSize = ulLength * 2;
    g_pusMusic = pusSong;
    g_ulPlaying = 0;

    g_sOutBuffers[0].pulData = 0;
    g_sOutBuffers[1].pulData = 0;

    if(SoundNextTone() != 0)
    {
        SoundBufferPlay(g_pulTxBuf, g_ulSize, BufferCallback);
        SoundBufferPlay(g_pulTxBuf, g_ulSize, BufferCallback);
    }
}
Example #2
0
//extern unsigned char set__;
void mad_synth_frame(struct mad_synth *synth, struct mad_frame /*const*/ *frame)
{
  unsigned int nch, ns;
  static int samplerate=0;
  void (*synth_frame)(struct mad_synth *, struct mad_frame /*const*/ *,
		      unsigned int, unsigned int);

  nch = MAD_NCHANNELS(&frame->header);
  ns  = MAD_NSBSAMPLES(&frame->header);

  synth->pcm.samplerate = frame->header.samplerate;
  
  //--set_dac_sample_rate(synth->pcm.samplerate);
  //while(g_ulFlags!=7);
  
  //if(set__)
  {
    vPortEnterCritical( );
    SoundSetFormat(frame->header.samplerate,16,1);
    //set__=0;
    vPortExitCritical( );
  }
  
  synth->pcm.channels   = nch;
  synth->pcm.length     = 32 * ns;
  samplerate = synth->pcm.samplerate;

  synth_frame = synth_full;

  if (frame->options & MAD_OPTION_HALFSAMPLERATE) {
    synth->pcm.samplerate /= 2;
    synth->pcm.length     /= 2;
    //--set_dac_sample_rate(synth->pcm.samplerate);
    vPortEnterCritical( );
    SoundSetFormat(frame->header.samplerate,16,1);
    vPortExitCritical( );
    synth_frame = synth_half;
  }

  synth_frame(synth, frame, nch, ns);
  synth->phase = (synth->phase + ns) % 16;
}
//*****************************************************************************
//
// The program main function.  It performs initialization, then handles wav
// file playback.
//
//*****************************************************************************
int
main(void)
{
    int nStatus;

    //
    // Set the system clock to run at 80MHz from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Give bget some memory to work with.
    //
    bpool(g_pulHeap, sizeof(g_pulHeap));

    //
    // Set the device pin out appropriately for this board.
    //
    PinoutSet();

    //
    // Configure the relevant pins such that UART0 owns them.
    //
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Open the UART for I/O
    //
    UARTStdioInit(0);

    UARTprintf("i2s_speex_enc\n");

    //
    // Configure and enable uDMA
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    SysCtlDelay(10);
    ROM_uDMAControlBaseSet(&sDMAControlTable[0]);
    ROM_uDMAEnable();

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Configure the I2S peripheral.
    //
    SoundInit(1);

    //
    // Set the format of the play back in the sound driver.
    //
    SoundSetFormat(AUDIO_RATE, AUDIO_BITS, AUDIO_CHANNELS);

    //
    // Print out some header information to the serial console.
    //
    UARTprintf("\ni2s_speex_enc Stellaris Example\n");
    UARTprintf("Streaming at %d %d bit ",SoundSampleRateGet(), AUDIO_BITS);

    if(AUDIO_CHANNELS == 2)
    {
        UARTprintf("Stereo\n");
    }
    else
    {
        UARTprintf("Mono\n");
    }

    //
    // Set the initial volume.
    //
    SoundVolumeSet(INITIAL_VOLUME_PERCENT);

    //
    // Initialize the Speex decoder.
    //
    SpeexDecodeInit();

    //
    // Set the default quality to 2.
    //
    g_iQuality = 2;

    //
    // Initialize the Speex encoder to Complexity of 1 and Quality 2.
    //
    SpeexEncodeInit(AUDIO_RATE, 1, g_iQuality);

    //
    // Initialize the audio buffers.
    //
    InitBuffers();

    //
    // Initialize the applications global state flags.
    //
    g_ulFlags = 0;

    //
    // Kick off a request for a buffer play back and advance the encoder
    // pointer.
    //
    SoundBufferRead(g_pucRecBuffer, RECORD_BUFFER_INC,
                    RecordBufferCallback);
    g_pucEncode += RECORD_BUFFER_INC;

    //
    // Kick off a second request for a buffer play back and advance the encode
    // pointer.
    //
    SoundBufferRead(&g_pucRecBuffer[RECORD_BUFFER_INC], RECORD_BUFFER_INC,
                    RecordBufferCallback);
    g_pucEncode += RECORD_BUFFER_INC;

    //
    // The rest of the handling occurs at interrupt time so the main loop will
    // simply stall here.
    //
    while(1)
    {
        //
        // Print a prompt to the console.  Show the CWD.
        //
        UARTprintf("\n> ");

        //
        // Get a line of text from the user.
        //
        UARTgets(g_cCmdBuf, sizeof(g_cCmdBuf));

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        nStatus = CmdLineProcess(g_cCmdBuf);

        //
        // Handle the case of bad command.
        //
        if(nStatus == CMDLINE_BAD_CMD)
        {
            UARTprintf("Bad command!\n");
        }

        //
        // Handle the case of too many arguments.
        //
        else if(nStatus == CMDLINE_TOO_MANY_ARGS)
        {
            UARTprintf("Too many arguments for command processor!\n");
        }

        //
        // Otherwise the command was executed.  Print the error
        // code if one was returned.
        //
        else if(nStatus != 0)
        {
            UARTprintf("Command returned error code \n");
        }
    }
}