コード例 #1
0
ファイル: sound.c プロジェクト: Brandon7357/rockbox
void sound_set_volume(int value)
{
    if (!audio_is_initialized)
        return;

#if defined(AUDIOHW_HAVE_CLIPPING)
    audiohw_set_volume(value);
#else
    sound_prescaler.volume = sound_value_to_cb(SOUND_VOLUME, value);
    set_prescaled_volume();
#endif
}
コード例 #2
0
ファイル: sound.c プロジェクト: IlVerz/rockbox
void sound_set_volume(int value)
{
    if(!audio_is_initialized)
        return;

#if defined(AUDIOHW_HAVE_CLIPPING)
    audiohw_set_volume(value);
#elif CONFIG_CPU == PNX0101
    int tmp = (60 - value * 4) & 0xff;
    CODECVOL = tmp | (tmp << 8);
#else
    current_volume = value * 10;     /* tenth of dB */
    set_prescaled_volume();
#endif
}
コード例 #3
0
ファイル: sound.c プロジェクト: IlVerz/rockbox
static void set_prescaled_volume(void)
{
    int prescale = 0;
    int l, r;

/* The codecs listed use HW tone controls but don't have suitable prescaler
 * functionality, so we let the prescaler stay at 0 for these, unless
 * SW tone controls are in use. This is to avoid needing the SW DSP just for
 * the prescaling.
 */
#if defined(HAVE_SW_TONE_CONTROLS) || !(defined(HAVE_WM8975) \
    || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
    || defined(HAVE_WM8758) || defined(HAVE_WM8985) || defined(HAVE_UDA1341))

#if defined(AUDIOHW_HAVE_BASS) && defined(AUDIOHW_HAVE_TREBLE)
    prescale = MAX(current_bass, current_treble);
#endif
#if defined(AUDIOHW_HAVE_EQ)
    int i;
    for (i = 0; i < AUDIOHW_EQ_BAND_NUM; i++)
        prescale = MAX(current_eq_band_gain[i], prescale);
#endif

    if (prescale < 0)
        prescale = 0;  /* no need to prescale if we don't boost
                          bass, treble or eq band */

    /* Gain up the analog volume to compensate the prescale gain reduction,
     * but if this would push the volume over the top, reduce prescaling
     * instead (might cause clipping). */
    if (current_volume + prescale > VOLUME_MAX)
        prescale = VOLUME_MAX - current_volume;
#endif

#if defined(AUDIOHW_HAVE_PRESCALER)
    audiohw_set_prescaler(prescale);
#else
    dsp_callback(DSP_CALLBACK_SET_PRESCALE, prescale);
#endif

    if (current_volume == VOLUME_MIN)
        prescale = 0;  /* Make sure the chip gets muted at VOLUME_MIN */

    l = r = current_volume + prescale;

    /* Balance the channels scaled by the current volume and min volume. */
    /* Subtract a dB from VOLUME_MIN to get it to a mute level */
    if (current_balance > 0)
    {
        l -= ((l - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE;
    }
    else if (current_balance < 0)
    {
        r += ((r - (VOLUME_MIN - ONE_DB)) * current_balance) / VOLUME_RANGE;
    }

#ifdef HAVE_SW_VOLUME_CONTROL
    dsp_callback(DSP_CALLBACK_SET_SW_VOLUME, 0);
#endif

#ifndef HAVE_SDL_AUDIO
#if CONFIG_CODEC == MAS3507D
    dac_volume(tenthdb2reg(l), tenthdb2reg(r), false);
#elif defined(HAVE_UDA1380) || defined(HAVE_WM8975) || defined(HAVE_WM8758) \
   || defined(HAVE_WM8711) || defined(HAVE_WM8721) || defined(HAVE_WM8731) \
   || defined(HAVE_WM8750) || defined(HAVE_WM8751) || defined(HAVE_AS3514) \
   || defined(HAVE_TSC2100) || defined(HAVE_AK4537) || defined(HAVE_UDA1341) \
   || defined(HAVE_CS42L55)
    audiohw_set_master_vol(tenthdb2master(l), tenthdb2master(r));
#if defined(HAVE_WM8975) || defined(HAVE_WM8758) \
    || (defined(HAVE_WM8751) && defined(TOSHIBA_GIGABEAT_F)) \
    || defined(HAVE_WM8985) || defined(HAVE_CS42L55)
    audiohw_set_lineout_vol(tenthdb2master(0), tenthdb2master(0));
#endif

#elif defined(HAVE_TLV320) || defined(HAVE_WM8978) || defined(HAVE_WM8985)
    audiohw_set_headphone_vol(tenthdb2master(l), tenthdb2master(r));
#elif defined(HAVE_JZ4740_CODEC) || defined(HAVE_SDL_AUDIO) || defined(ANDROID)
    audiohw_set_volume(current_volume);
#endif
#else /* HAVE_SDL_AUDIO */
    audiohw_set_volume(current_volume);
#endif /* !HAVE_SDL_AUDIO */
}
コード例 #4
0
ファイル: sound.c プロジェクト: Brandon7357/rockbox
static void set_prescaled_volume(void)
{
#if defined(TONE_PRESCALER) || !defined(AUDIOHW_HAVE_MONO_VOLUME)
    const int minvol = sound_value_to_cb(SOUND_VOLUME, sound_min(SOUND_VOLUME));
#endif
    int volume = sound_prescaler.volume;

#if defined(TONE_PRESCALER)
    int prescale = 0;

    /* Note: Having Tone + EQ isn't prohibited */
#if defined(AUDIOHW_HAVE_BASS) && defined(AUDIOHW_HAVE_TREBLE)
    prescale = MAX(sound_prescaler.bass, sound_prescaler.treble);
#endif

#if defined(AUDIOHW_HAVE_EQ)
    for (int i = 0; i < AUDIOHW_EQ_BAND_NUM; i++)
        prescale = MAX(sound_prescaler.eq_gain[i], prescale);
#endif

    if (prescale < 0)
        prescale = 0;  /* no need to prescale if we don't boost
                          bass, treble or eq band */

    /* Gain up the analog volume to compensate the prescale gain reduction,
     * but if this would push the volume over the top, reduce prescaling
     * instead (might cause clipping). */
    const int maxvol = sound_value_to_cb(SOUND_VOLUME, sound_max(SOUND_VOLUME));

    if (volume + prescale > maxvol)
        prescale = maxvol - volume;

    audiohw_set_prescaler(prescale);

    if (volume <= minvol)
        prescale = 0;  /* Make sure the audio gets muted */

#ifndef AUDIOHW_HAVE_MONO_VOLUME
    /* At the moment, such targets have lousy volume resolution and so minute
       boost won't work how we'd like */
    volume += prescale;
#endif
#endif /* TONE_PRESCALER */

#if defined(AUDIOHW_HAVE_MONO_VOLUME)
    audiohw_set_volume(volume);
#else /* Stereo volume */
    int l = volume, r = volume;

    /* Balance the channels scaled by the current volume and min volume */
    int balance = sound_prescaler.balance; /* percent */

    if (balance > 0)
    {
        l -= (l - minvol) * balance / 100;
    }
    else if (balance < 0)
    {
        r += (r - minvol) * balance / 100;
    }

    audiohw_set_volume(l, r);
#endif /* AUDIOHW_HAVE_MONO_VOLUME */

#if defined(AUDIOHW_HAVE_LINEOUT)
    /* For now, lineout stays at unity */
    audiohw_set_lineout_volume(0, 0);
#endif /* AUDIOHW_HAVE_LINEOUT */
}