예제 #1
0
파일: main.c 프로젝트: wuwx/simba
static int test_pcm1611s(struct harness_t *harness_p)
{
#if !defined(SKIP_TEST_PCM1611S)

    int i;
    int samples_per_second = 2 * 11025;
    struct dac_driver_t dac;

    BTASSERT(dac_init(&dac,
                      &dac_0_dev,
                      &pin_0_dev,
                      &pin_1_dev,
                      samples_per_second) == 0);

    for (i = 0; i < membersof(dac_gen_pcm1611s); i += 4096) {
        memcpy(samples, &dac_gen_pcm1611s[i], sizeof(samples));
        BTASSERT(dac_async_convert(&dac,
                                   (uint32_t *)samples,
                                   4096 / 2) == 0);
    }

    BTASSERT(dac_async_wait(&dac) == 0);

    return (0);

#else
    
    return (1);
    
#endif
}
예제 #2
0
파일: main.c 프로젝트: wuwx/simba
static int test_sine_440_hz(struct harness_t *harness_p)
{
#if !defined(SKIP_TEST_SINE_440_HZ)
    
    int i;
    float sample;
    int samples_per_second = (membersof(dac_gen_sine) * 440);
    struct dac_driver_t dac;
    int total_number_of_samples;

    BTASSERT(dac_init(&dac,
                      &dac_0_dev,
                      &pin_0_dev,
                      NULL,
                      samples_per_second) == 0);

    /* Samples are in the range -1.0 to 1.0. Convert them to the range
       0 to AMPLITUDE_MAX. */
    for (i = 0; i < membersof(samples); i++) {
        sample = dac_gen_sine[i % membersof(dac_gen_sine)];
        samples[i] =  AMPLITUDE_MAX * ((sample + 1.0) / 2.0);
    }

    std_printf(FSTR("Converting %d samples.\r\n"), (int)membersof(samples));
    BTASSERT(dac_convert(&dac, (uint32_t *)samples, membersof(samples) / 2) == 0);

    /* Converting the signal on the DAC0-pin for 5 seconds. */
    total_number_of_samples = (5 * samples_per_second);
    std_printf(FSTR("Converting %d samples.\r\n"),
               total_number_of_samples);

    for (i = 0; i < total_number_of_samples; i += membersof(samples)) {
        BTASSERT(dac_async_convert(&dac,
                                   (uint32_t *)samples,
                                   membersof(samples) / 2) == 0);
        std_printf(FSTR("Samples left = %d\r\n"), total_number_of_samples - i);
    }

    std_printf(FSTR("Waiting for last samples to be converted\r\n"));

    BTASSERT(dac_async_wait(&dac) == 0);
    
    return (0);

#else

    (void)dac_gen_sine;
    
    return (1);
    
#endif
}
예제 #3
0
/**
 * Read from the file for the current song and add samples to the
 * DAC. In case the song ends, open the next song as preparation for
 * the next call to this function.
 */
static int play_chunk(struct music_player_t *self_p)
{
    const char *path_p;
    uint32_t *buf_p;
    size_t size;
    int i;

    /* Read samples from the file. */
    buf_p = self_p->samples.buf[self_p->samples.index];
    self_p->samples.index++;
    self_p->samples.index %= membersof(self_p->samples.buf);
    size = fat16_file_read(&self_p->file,
                           buf_p,
                           sizeof(self_p->samples.buf[0]));

    /* Optional down sampling of the read samples. */
    if (self_p->down_sampling_mask != 0xfffffffful) {
        for (i = 0; i < size / 4; i++) {
            buf_p[i] &= self_p->down_sampling_mask;
        }
    }

    if (size > 0) {
        /* Add samples for DAC convertion. */
        dac_async_convert(self_p->dac_p, buf_p, size / 4);
    } else {
        /* Start playing the next file in the queue. */
        fat16_file_close(&self_p->file);

        if ((path_p = self_p->cb.next_song_path_p(self_p->cb.arg_p)) != NULL) {
            strcpy(self_p->path, path_p);
            std_printf(FSTR("Playing | %s\r\n"), self_p->path);
            fat16_file_open(self_p->fat16_p, &self_p->file, path_p, O_READ);
        } else {
            self_p->state = STATE_IDLE;
        }
    }

    return (0);
}