VirtualBox

Changeset 7525 in vbox for trunk/src/VBox/Devices/Audio


Ignore:
Timestamp:
Mar 25, 2008 10:17:49 AM (17 years ago)
Author:
vboxsync
Message:

Solaris host audio: fixes and integrated into Main. Needs more
rigorous testing, only tested locally here. BFE still acts weird.

Location:
trunk/src/VBox/Devices/Audio
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/audio.c

    r6598 r7525  
    18701870        case AUD_MIXER_PCM:
    18711871            name = "PCM_OUT";
     1872            vol  = &pcm_out_volume;
    18721873            break;
    18731874        case AUD_MIXER_LINE_IN:
  • trunk/src/VBox/Devices/Audio/solaudio.c

    r7454 r7525  
    5959} conf =
    6060{
    61     INIT_FIELD (cbBuffer =) 8912,
     61    INIT_FIELD (cbBuffer =) 4352,
    6262};
    6363
     
    123123
    124124
    125 static char *solaudio_getdevice ()
     125static char *solaudio_getdevice (void)
    126126{
    127127    /* This is for multiple audio devices where env. var determines current one,
    128128     * otherwise else we fallback to default.
    129129     */
    130     char *pszAudioDev = RTEnvGet("AUDIODEV");
     130    const char *pszAudioDev = RTEnvGet("AUDIODEV");
    131131    if (pszAudioDev)
    132132        return RTStrDup(pszAudioDev);
     
    141141    int AudioCtl;
    142142    struct stat FileStat;
    143     const char *pszAudioDev = NULL;
    144     const char *pszAudioCtl = "/dev/audioctl";
     143    char *pszAudioDev = NULL;
     144    char *pszAudioCtl = NULL;
    145145    audio_info_t AudioInfo;
    146146
     
    149149    {
    150150        LogRel(("solaudio: solaudio_getdevice() failed to return a valid device.\n"));
    151         goto err;
     151        return -1;
    152152    }
    153153
     
    155155    {
    156156        LogRel(("solaudio: failed to stat %s\n", pszAudioDev));
    157         goto err;
     157        goto err2;
    158158    }
    159159
     
    161161    {
    162162        LogRel(("solaudio: invalid mode for %s\n", pszAudioDev));
    163         goto err;
     163        goto err2;
    164164    }
    165165
     
    168168    {
    169169        LogRel(("solaudio: failed to open %s\n", pszAudioDev));
    170         goto err;
    171     }
    172 
     170        goto err2;
     171    }
     172
     173    RTStrAPrintf(&pszAudioCtl, "%sctl", pszAudioDev);
    173174    AudioCtl = open(pszAudioCtl, O_WRONLY | O_NONBLOCK);
    174175    if (AudioCtl < 0)
     
    193194    AudioInfo.play.buffer_size = info->play.buffer_size;
    194195    AudioInfo.play.gain = AUDIO_MAX_GAIN;
    195     AudioInfo.play.balance = AUDIO_MID_BALANCE;
    196196    if (ioctl(AudioDev, AUDIO_SETINFO, &AudioInfo) < 0)
    197197    {
     
    204204    *pfd = AudioDev;
    205205    *pctl_fd = AudioCtl;
     206    RTStrFree(pszAudioDev);
     207    RTStrFree(pszAudioCtl);
    206208    return 0;
    207209
    208210err:
     211    RTStrFree(pszAudioCtl);
     212err2:
    209213    RTStrFree(pszAudioDev);
    210214    return -1;
     
    224228    AudioInfo.play.channels = as->nchannels;
    225229    AudioInfo.play.precision = aud_to_solfmt(as->fmt);
     230#if 0
     231    /* Not really needed. */
     232    int cbPerSample = (AudioInfo.play.channels * AudioInfo.play.precision) / 8;
     233    int cbPerSecond = cbPerSample * AudioInfo.play.sample_rate;
     234    AudioInfo.play.buffer_size = cbPerSecond > 131072 ? conf.cbBuffer : conf.cbBuffer / 2;
     235#endif
    226236    AudioInfo.play.buffer_size = conf.cbBuffer;
     237
    227238    if (as->fmt == AUD_FMT_U8)
    228239        AudioInfo.play.encoding = AUDIO_ENCODING_LINEAR8;
     
    260271static void solaudio_stop (solaudioVoiceOut *sol)
    261272{
     273    audio_info_t AudioInfo;
    262274    LogFlow(("solaudio: stop\n"));
    263275    if (sol->AudioDev < 0 || sol->AudioCtl < 0)
     
    269281    if (ioctl(sol->AudioCtl, I_SETSIG, 0) < 0)
    270282    {
    271         LogRel(("solaudio: failed to stop signalling\n"));
     283        Log(("solaudio: failed to stop signalling\n"));
    272284        return;
    273285    }
     
    275287    if (ioctl(sol->AudioDev, I_FLUSH, FLUSHW) < 0)
    276288    {
    277         Log(("solaudio: failed to drop unplayed buffers\n"));
     289        LogRel(("solaudio: failed to drop unplayed buffers\n"));
    278290        return;
    279291    }
     292
     293    AUDIO_INITINFO(&AudioInfo);
     294    AudioInfo.play.samples = 0;
     295    AudioInfo.play.pause = 0;
     296    AudioInfo.play.eof = 0;
     297    AudioInfo.play.error = 0;
     298    sol->cBuffersPlayed = 0;
     299    if (ioctl(sol->AudioDev, AUDIO_SETINFO, &AudioInfo) < 0)
     300    {
     301        LogRel(("solaudio: AUDIO_SETINFO failed during stop.\n"));
     302        return;
     303    }
     304}
     305
     306
     307static void solaudio_fini_out (HWVoiceOut *hw)
     308{
     309    solaudioVoiceOut *sol = (solaudioVoiceOut *) hw;
     310    solaudio_stop (sol);
    280311
    281312    close(sol->AudioDev);
     
    283314    close(sol->AudioCtl);
    284315    sol->AudioCtl = -1;
    285     sol->cBuffersPlayed = 0;
    286316    if (sol->pPCMBuf)
    287317    {
     
    289319        sol->pPCMBuf = NULL;
    290320    }
    291 }
    292 
    293 
    294 static void solaudio_fini_out (HWVoiceOut *hw)
    295 {
    296     solaudioVoiceOut *sol = (solaudioVoiceOut *) hw;
    297     solaudio_stop (sol);
     321
    298322    LogFlow(("solaudio: fini_out done\n"));
    299323}
     
    312336    }
    313337
    314     cbBuffer = AudioInfo.play.buffer_size * (2 + AudioInfo.play.eof - sol->cBuffersPlayed);
     338    if (sol->cBuffersPlayed - AudioInfo.play.eof <= 2)
     339        cbBuffer = AudioInfo.play.buffer_size;
    315340
    316341    LogFlow(("avail: eof=%d samples=%d bufsize=%d bufplayed=%d avail=%d\n", AudioInfo.play.eof, AudioInfo.play.samples,
     
    328353
    329354    WaitTimeSpec.tv_sec = 0;
    330     WaitTimeSpec.tv_nsec = 1000000;
    331 
    332     while (AudioInfo.play.eof < pSol->cBuffersPlayed - 2)
     355    WaitTimeSpec.tv_nsec = 100000000;
     356
     357    while (AudioInfo.play.eof + 10 < pSol->cBuffersPlayed)
    333358    {
    334359        nanosleep(&WaitTimeSpec, NULL);
     
    373398            break;
    374399
     400        /* Increment eof marker for synchronous buffer processed */
     401        write (pSol->AudioDev, NULL, 0);
     402        pSol->cBuffersPlayed++;
     403
    375404        hw->rpos   = (hw->rpos + csToWrite) % hw->samples;
    376405        csSamples -= csToWrite;
    377406    }
    378     /* Increment eof marker for synchronous buffer processed */
    379     write (pSol->AudioDev, NULL, 0);
    380     pSol->cBuffersPlayed++;
    381407    return csDecr;
    382408}
     
    392418            /* reset the eof marker and samples markers */
    393419            audio_info_t AudioInfo;
     420            LogFlow(("solaudio: voice_enable\n"));
    394421            AUDIO_INITINFO(&AudioInfo);
    395422            ioctl(pSol->AudioDev, AUDIO_GETINFO, &AudioInfo);
     
    400427
    401428            audio_pcm_info_clear_buf(&hw->info, pSol->pPCMBuf, hw->samples);
    402             LogFlow(("solaudio: voice_enable\n"));
    403429            break;
    404430        }
     
    429455static void solaudio_audio_fini (void *opaque)
    430456{
    431     (void) opaque;
    432 }
    433 
    434 
    435 static struct audio_pcm_ops solaudio_pcm_ops = {
     457    NOREF(opaque);
     458}
     459
     460
     461static struct audio_pcm_ops solaudio_pcm_ops =
     462{
    436463    solaudio_init_out,
    437464    solaudio_fini_out,
     
    447474};
    448475
    449 static struct audio_option solaudio_options[] = {
     476static struct audio_option solaudio_options[] =
     477{
    450478    {"BUFFER_SIZE", AUD_OPT_INT, &conf.cbBuffer,
    451479     "Size of the buffer in bytes", NULL, 0},
     
    453481};
    454482
    455 struct audio_driver solaudio_audio_driver = {
     483struct audio_driver solaudio_audio_driver =
     484{
    456485    INIT_FIELD (name           = ) "solaudio",
    457486    INIT_FIELD (descr          = ) "SolarisAudio http://sun.com",
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette