Ejemplo n.º 1
0
void MUSIC_Play(enum Music music)
{
    /* NOTE: We need to do all this even if volume is zero, because
       the haptic sensor may be enabled */
    num_notes = 0;
    next_note = 1;
    Volume = Transmitter.volume * 10;
    char filename[] = "media/sound.ini\0\0\0"; // placeholder for longer folder name
    #ifdef _DEVO12_TARGET_H_
    static u8 checked;
        if(!checked) {
            FILE *fh;
            fh = fopen("mymedia/sound.ini", "r");
            if(fh) {
                sprintf(filename, "mymedia/sound.ini");
                fclose(fh);
            }
            checked = 1;
        }
    #endif
    if(CONFIG_IniParse(filename, ini_handler, (void *)sections[music])) {
        printf("ERROR: Could not read %s\n", filename);
        return;
    }
    if(! num_notes)
        return;
    SOUND_SetFrequency(note_map[Notes[0].note].note, Volume);
    SOUND_Start((u16)Notes[0].duration * 10, next_note_cb);
}
Ejemplo n.º 2
0
void MUSIC_Play(u16 music)
{
#if HAS_EXTENDED_AUDIO
    // Play audio for switch
    if ( music > MUSIC_TOTAL ) {
        if (AUDIO_VoiceAvailable())
            AUDIO_AddQueue(music);
        return;
    }
    playback_device = AUDDEV_UNDEF;
#endif
    vibrate = 1;	// Haptic sensor set to on as default

    /* NOTE: We need to do all this even if volume is zero, because
       the haptic sensor may be enabled */

    if (MUSIC_GetSound(music)) return;


#if HAS_EXTENDED_AUDIO
    if ( !(playback_device == AUDDEV_BUZZER) ) {
        if (  AUDIO_VoiceAvailable() && AUDIO_AddQueue(music) ) {
            if ((playback_device == AUDDEV_EXTAUDIO) || (playback_device == AUDDEV_UNDEF)) {
                Volume = 0;
                return;
            }
        }
    }
#endif

    if(! num_notes) return;
    SOUND_SetFrequency(note_map[Notes[0].note].note, Volume);
    SOUND_Start((u16)Notes[0].duration * 10, next_note_cb, vibrate);
}
Ejemplo n.º 3
0
void MUSIC_Beep(char* note, u16 duration, u16 interval, u8 count)
{
    vibrate = 1; // Haptic sensor set to on as default
    u8 tone=0,i;
    next_note = 1;
    Volume = Transmitter.volume * 10;
    if(! count)
        return;
    if(count > sizeof(Notes)/2)
        count = sizeof(Notes)/2;
    for(i = 0; i < NUM_NOTES; i++) {
        if(strcasecmp(note_map[i].str, note) == 0) {
            tone = i;
            break;
        }
    }
    num_notes = count*2;
    for(i=0; i<count; i++) {
        Notes[i*2].note = tone;
        Notes[i*2].duration = duration / 10;
        Notes[(i*2)+1].note = 0;
        Notes[(i*2)+1].duration = interval / 10;
    }
    SOUND_SetFrequency(note_map[Notes[0].note].note, Volume);
    SOUND_Start((u16)Notes[0].duration * 10, next_note_cb, vibrate);
}
Ejemplo n.º 4
0
u16 next_note_cb() {
    if (next_note == num_notes)
        return 0;
    SOUND_SetFrequency(note_map[Notes[next_note].note].note, Volume);
    return Notes[next_note++].duration * 10;
}
Ejemplo n.º 5
0
unsigned MIXER_UpdateTrim(u32 buttons, unsigned flags, void *data)
{
#define TRIM_MUSIC_DURATION 100
#define START_TONE 1000
    (void)data;
    int i;
    int orig_step_size = 1;
    int tmp;
    unsigned reach_end = 0; // reach either 100 , 0, or -100
    if (flags & BUTTON_LONGPRESS) {
        if (orig_step_size == 1)
            orig_step_size = 9;
        else if (orig_step_size == 9)
            orig_step_size = 10;
    }
    if (! orig_step_size)
        return 1;
    unsigned volume = 10 * Transmitter.volume;
    for (i = 0; i < NUM_TRIMS; i++) {
        int step_size = orig_step_size;
        reach_end = 0;
        int neg_button = CHAN_ButtonIsPressed(buttons, Model.trims[i].neg);
        if (neg_button || CHAN_ButtonIsPressed(buttons, Model.trims[i].pos)) {
            if (Model.trims[i].step > 190) {
                _trim_as_switch(flags, i, neg_button);
                continue;
            }
            if (flags & BUTTON_RELEASE)
                continue;
            int max = 100;
            if (Model.trims[i].step >= 100) {
                step_size = Model.trims[i].step - 90;
            } else if (Model.trims[i].step > 10) {
                step_size = step_size * Model.trims[i].step / 10;
            }
            if (neg_button)
                step_size = -step_size;
            s8 *value = MIXER_GetTrim(i);
            tmp = (int)(*value) + step_size;
            //print_buttons(buttons);
            if ((int)*value > 0 && tmp <= 0) {
                *value = 0;
                reach_end = 1;
            } else if ((int)*value < 0 && tmp >= 0) {
                *value = 0;
                reach_end = 1;
            } else if (tmp > max) {
                *value = 100;
                reach_end = 1;
            } else if (tmp < -max) {
                *value = -100;
                reach_end = 1;
            } else {
                *value = tmp;
            }

            if (reach_end && (flags & BUTTON_LONGPRESS))
                BUTTON_InterruptLongPress();

            if (Model.trims[i].value[0] == 0) {
                SOUND_SetFrequency(3951, volume);
                SOUND_StartWithoutVibrating(TRIM_MUSIC_DURATION, NULL);
            }
            else if (CLOCK_getms()- last_trim_music_time > TRIM_MUSIC_DURATION + 50) {  // Do not beep too frequently
                last_trim_music_time = CLOCK_getms();
                tmp = (*value >= 0) ? *value : -*value;
                if (step_size >=9 || step_size <= -9)
                    SOUND_SetFrequency(START_TONE + tmp * 10, volume); // start from "c2" tone, frequence = 1000
                else  {  //  for small step change: generate 2 different tone for closing to/away from mid-point
                    if (*value < 0)
                        step_size = -step_size;
                    u16 tone = START_TONE + 300;
                    if (step_size < 0)
                        tone = START_TONE;
                    SOUND_SetFrequency(tone, volume);
                    //printf("tone: %d\n\n", tone);
                }

                SOUND_StartWithoutVibrating(TRIM_MUSIC_DURATION, NULL);
            }
        }
    }
    return 1;
}