Esempio n. 1
0
void get_more(unsigned char** start, size_t* size)
{
#ifndef SYNC
    if(lastswap != swap)
    {
        midi_debug("Buffer miss!"); /* Comment out the midi_debug to make missses less noticable. */
    }

#else
    synthbuf();  /* For some reason midiplayer crashes when an update is forced */
#endif

    *size = samples_in_buf*sizeof(int32_t);
#ifndef SYNC
    *start = (unsigned char*)((swap ? gmbuf : gmbuf + BUF_SIZE));
    swap = !swap;
#else
    *start = (unsigned char*)(gmbuf);
#endif
}
Esempio n. 2
0
void get_more(unsigned char** start, size_t* size)
{
#ifndef SYNC
    if(lastswap!=swap)
    {
//        printf("Buffer miss!"); // Comment out the printf to make missses less noticable.
    }

#else
    synthbuf();  // For some reason midiplayer crashes when an update is forced
#endif

    *size = BUF_SIZE*sizeof(short);
#ifndef SYNC
    *start = (unsigned char*)((swap ? gmbuf : gmbuf + BUF_SIZE));
    swap=!swap;
#else
    *start = (unsigned char*)(gmbuf);
#endif
}
Esempio n. 3
0
static void get_more(const void** start, size_t* size)
{
#ifndef SYNC
    if(lastswap != swap)
    {
        midi_debug("Buffer miss!"); /* Comment out the midi_debug to make missses less noticable. */
    }

#else
    synthbuf();  /* For some reason midiplayer crashes when an update is forced */
#endif

    *size = samples_in_buf*sizeof(int32_t);
#ifndef SYNC
    *start = swap ? gmbuf : gmbuf + BUF_SIZE;
    swap = !swap;
#else
    *start = gmbuf;
#endif
    if (samples_in_buf==0) {
        *start = NULL;
        quit = true;    /* this was the last buffer to play */
    }
}
Esempio n. 4
0
static int midimain(const void * filename)
{
    int a, notes_used, vol;
    bool is_playing = true;  /* false = paused */

#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
    rb->cpu_boost(true);
#endif
    midi_debug("Loading file");
    mf = loadFile(filename);

    if (mf == NULL)
    {
        midi_debug("Error loading file.");
#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
        rb->cpu_boost(false);
#endif
        return -1;
    }

    if (initSynth(mf, ROCKBOX_DIR "/patchset/patchset.cfg",
        ROCKBOX_DIR "/patchset/drums.cfg") == -1)
    {
#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
        rb->cpu_boost(false);
#endif
        return -1;
    }

    rb->pcm_play_stop();
#if INPUT_SRC_CAPS != 0
    /* Select playback */
    rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
    rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);
#endif
    rb->pcm_set_frequency(SAMPLE_RATE); /* 44100 22050 11025 */

    /*
        * tick() will do one MIDI clock tick. Then, there's a loop here that
        * will generate the right number of samples per MIDI tick. The whole
        * MIDI playback is timed in terms of this value.. there are no forced
        * delays or anything. It just produces enough samples for each tick, and
        * the playback of these samples is what makes the timings right.
        *
        * This seems to work quite well. On a laptop, anyway.
        */

    midi_debug("Okay, starting sequencing");

    bpm = mf->div*1000000/tempo;
    number_of_samples = SAMPLE_RATE/bpm;

    /* Skip over any junk in the beginning of the file, so start playing */
    /* after the first note event */
    do
    {
        notes_used = 0;
        for (a = 0; a < MAX_VOICES; a++)
            if (voices[a].isUsed)
                notes_used++;
        tick();
    } while (notes_used == 0);

#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
    rb->cpu_boost(false);
#endif

    playing_time = 0;
    samples_this_second = 0;

    synthbuf();
    rb->pcm_play_data(&get_more, NULL, NULL, 0);

    while (!quit)
    {
    #ifndef SYNC
        synthbuf();
    #endif
        rb->yield();

        /* Prevent idle poweroff */
        rb->reset_poweroff_timer();

        /* Code taken from Oscilloscope plugin */
        switch (rb->button_get(false))
        {
            case MIDI_VOL_UP:
            case MIDI_VOL_UP | BUTTON_REPEAT:
            {
                vol = rb->global_settings->volume;
                if (vol < rb->sound_max(SOUND_VOLUME))
                {
                    vol++;
                    rb->sound_set(SOUND_VOLUME, vol);
                    rb->global_settings->volume = vol;
                }
                break;
            }

            case MIDI_VOL_DOWN:
            case MIDI_VOL_DOWN | BUTTON_REPEAT:
            {
                vol = rb->global_settings->volume;
                if (vol > rb->sound_min(SOUND_VOLUME))
                {
                    vol--;
                    rb->sound_set(SOUND_VOLUME, vol);
                    rb->global_settings->volume = vol;
                }
                break;
            }

            case MIDI_REWIND:
            {
                /* Rewinding is tricky. Basically start the file over */
                /* but run through the tracks without the synth running */
                rb->pcm_play_stop();
#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
                rb->cpu_boost(true);
#endif
                seekBackward(5);
#if defined(HAVE_ADJUSTABLE_CPU_FREQ)
                rb->cpu_boost(false);
#endif
                lastswap = !swap;
                synthbuf();
                midi_debug("Rewind to %d:%02d\n", playing_time/60, playing_time%60);
                if (is_playing)
                    rb->pcm_play_data(&get_more, NULL, NULL, 0);
                break;
            }

            case MIDI_FFWD:
            {
                rb->pcm_play_stop();
                seekForward(5);
                lastswap = !swap;
                synthbuf();
                midi_debug("Skip to %d:%02d\n", playing_time/60, playing_time%60);
                if (is_playing)
                    rb->pcm_play_data(&get_more, NULL, NULL, 0);
                break;
            }

            case MIDI_PLAYPAUSE:
            {
                if (is_playing)
                {
                    midi_debug("Paused at %d:%02d\n", playing_time/60, playing_time%60);
                    is_playing = false;
                    rb->pcm_play_stop();
                } else
                {
                    midi_debug("Playing from %d:%02d\n", playing_time/60, playing_time%60);
                    is_playing = true;
                    rb->pcm_play_data(&get_more, NULL, NULL, 0);
                }
                break;
            }

#ifdef MIDI_RC_QUIT
            case MIDI_RC_QUIT:
#endif
            case MIDI_QUIT:
                quit = true;
        }
    }
    return 0;
}
Esempio n. 5
0
int beatboxmain()
{
    int vol=0;


    numberOfSamples=44100/10;
    synthbuf();
    rb->pcm_play_data(&get_more, NULL, 0);

    rb->lcd_set_background(0x000000);
    rb->lcd_clear_display();

    resetPosition();

    int i, j;

    /* Start at 16 cells/loop for now. User can un-loop if more are needed */
    for(i=0; i<V_NUMCELLS; i++)
        trackData[16][i] = VAL_LOOP;


/*  Very very rough beat to 'Goodbye Horses'
    trackData[16][3] = VAL_LOOP;
    trackData[16][2] = VAL_LOOP;

    trackData[0][3] = 1;
    trackData[4][3] = 1;
    trackData[8][3] = 1;
    trackData[9][3] = 1;
    trackData[12][3] = 1;
    trackData[13][3] = 1;

    trackData[2][2] = 1;
    trackData[6][2] = 1;
    trackData[10][2] = 1;
    trackData[14][2] = 1;
*/

    drawGrid();
    showDrumName(yCursor);
    updateDisplay();
    redrawScreen(1);


    while(!quit)
    {
    #ifndef SYNC
        synthbuf();
    #endif
        rb->yield();

        if(stepFlag)
        {
            advancePosition();
            sendEvents();
            updateDisplay();
            redrawScreen(0);
            stepFlag=0;
        }

        /* Prevent idle poweroff */
        rb->reset_poweroff_timer();

        /* Code taken from Oscilloscope plugin */
        switch(rb->button_get(false))
        {
        /*
                case BTN_UP:
                case BTN_UP | BUTTON_REPEAT:
                    vol = rb->global_settings->volume;
                    if (vol < rb->sound_max(SOUND_VOLUME))
                    {
                        vol++;
                        rb->sound_set(SOUND_VOLUME, vol);
                        rb->global_settings->volume = vol;
                    }
                    break;

                case BTN_DOWN:
                case BTN_DOWN | BUTTON_REPEAT:
                    vol = rb->global_settings->volume;
                    if (vol > rb->sound_min(SOUND_VOLUME))
                    {
                        vol--;
                        rb->sound_set(SOUND_VOLUME, vol);
                        rb->global_settings->volume = vol;
                    }
                    break;

                case BTN_RIGHT:
                {
                    //pressNote(9, 40, 127);
                 //   resetPosition();
                    advancePosition();
                    sendEvents();
                    updateDisplay();
                    redrawScreen(0);
                    break;
                }

                case BUTTON_LEFT:
                {

//                    isPlaying=1;
                    resetPosition();
                    updateDisplay();
                    redrawScreen(0);
                    //pressNote(9, 39, 127);
                    break;
                }
*/

                case BEATBOX_UP:
                case BEATBOX_UP | BUTTON_REPEAT:
                {
                    if(editState == EDITSTATE_PATTERN)
                    {
                        if(yCursor > 0)
                        {
                            yCursor--;
                            showDrumName(yCursor);
                            updateDisplay();
                            redrawScreen(0);
                        }
                    }
                    break;
                }

                case BEATBOX_DOWN:
                case BEATBOX_DOWN | BUTTON_REPEAT:
                {
                    if(editState == EDITSTATE_PATTERN)
                    {
                        if(yCursor < V_NUMCELLS-1)
                        {
                            yCursor++;
                            showDrumName(yCursor);
                            updateDisplay();
                            redrawScreen(0);
                        }
                    }
                    break;
                }

                case BEATBOX_LEFT:
                case BEATBOX_LEFT | BUTTON_REPEAT:
                {
                    if(editState == EDITSTATE_PATTERN)
                    {
                        if(xCursor > 0)
                        {
                            xCursor--;
                            updateDisplay();
                            redrawScreen(0);
                        }
                    }
                    break;
                }

                case BEATBOX_RIGHT:
                case BEATBOX_RIGHT | BUTTON_REPEAT:
                {
                    if(editState == EDITSTATE_PATTERN)
                    {
                        if(xCursor < H_NUMCELLS-1)
                        {
                            xCursor++;
                            updateDisplay();
                            redrawScreen(0);
                        }
                    }
                    break;
                }

                case BEATBOX_SELECT:
                {
                    if(editState == EDITSTATE_PATTERN)
                    {
                        int cv = trackData[xCursor][yCursor];
                        cv++;
                        if(cv > VAL_LOOP)
                            cv = VAL_NONE;

                        trackData[xCursor][yCursor] = cv;

                        updateDisplay();
                        redrawScreen(0);
                    }
                    break;
                }


                case BEATBOX_PLAY:
                {
                    if(playState == STATE_PLAYING)
                        playState = STATE_PAUSED;
                    else
                    {
                        updateDisplay();
                        redrawScreen(0);
                        sendEvents();
                        playState = STATE_PLAYING;
                    }
                    break;
                }

                case BEATBOX_STOP:
                {
                    if(playState == STATE_STOPPED)
                    {
                        quit=1;
                    } else
                    {
                        playState =STATE_STOPPED;
                        resetPosition();
                        updateDisplay();
                        redrawScreen(0);
                    }
                    break;
                }
        }


    }

    return 0;
}