Skip to contentSkip to conversation

Trigger Callback

DISCUSSION Julien Bramary 3 participants 5 messages Aug 1, 2006 – Aug 2, 2006

lore
Share & tools
lore
#0 lore raw

I'm an Alsa beginner and I'm trying to write an alsa driver for an embedded dac on ARM.

Quoted 1 line

From Iwai's doc:

/* trigger callback */
static int snd_mychip_pcm_trigger(struct snd_pcm_substream *substream, int cmd)

{
    switch (cmd) {
    case SNDRV_PCM_TRIGGER_START:
            // do something to start the PCM engine
            break;
    case SNDRV_PCM_TRIGGER_STOP:
            // do something to stop the PCM engine
            break;
    default:
            return -EINVAL;
    }
}

My question here is,
What are we supposed to do to start the PCM engine? Because, I'm currently doing nothing, and yet it starts anyway... I'd like to understand to have more control.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#1 lore raw
Quoted 19 lines · Julien Bramary

I'm an Alsa beginner and I'm trying to write an alsa driver for an embedded dac on ARM.

Quoted 1 line

From Iwai's doc:

/* trigger callback */
static int snd_mychip_pcm_trigger(struct snd_pcm_substream *substream, int cmd)

{
    switch (cmd) {
    case SNDRV_PCM_TRIGGER_START:
            // do something to start the PCM engine
            break;
    case SNDRV_PCM_TRIGGER_STOP:
            // do something to stop the PCM engine
            break;
    default:
            return -EINVAL;
    }
}
Quoted 4 lines

My question here is,
What are we supposed to do to start the PCM engine? Because, I'm currently doing nothing, and yet it starts anyway... I'd like to understand to have more control.

"PCM engine" refers to the hardware's PCM engine, not ALSA's. It's 100% device dependent - you need to consult the docs for your sound device to determine how to start the PCM.

Lee

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#2 lore raw
Quoted 5 lines · Lee Revell
Quoted 5 lines
Quoted 5 lines

"PCM engine" refers to the hardware's PCM engine, not ALSA's. It's 100% device dependent - you need to consult the docs for your sound device to determine how to start the PCM.

Lee

Thanks, I see now why it starts, I'm doing some inits in my dac in the open callback... I should do those here in the trigger.

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#3 lore raw

At Tue, 01 Aug 2006 21:14:24 +0100,

Quoted 10 lines · Julien Bramary
Quoted 5 lines · Lee Revell
Quoted 5 lines
Quoted 5 lines

"PCM engine" refers to the hardware's PCM engine, not ALSA's. It's 100% device dependent - you need to consult the docs for your sound device to determine how to start the PCM.

Lee

Thanks, I see now why it starts, I'm doing some inits in my dac in the open callback... I should do those here in the trigger.

Remember that the trigger callback is designed really as a "trigger". That is, it should be executed as shortly as possible. The callback is even in the atomic context within spinlock and irq disablement, so any function that my sleep shall cause lockup.

If you need to allocate something, it should be done in either open, hw_params or prepare callback. Only start and stop are done in trigger callback.

Takashi

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#4 lore raw
Quoted 21 lines · Takashi Iwai

At Tue, 01 Aug 2006 21:14:24 +0100,

Quoted 12 lines · Julien Bramary
Quoted 6 lines · Lee Revell
Quoted 6 lines
Quoted 5 lines

"PCM engine" refers to the hardware's PCM engine, not ALSA's. It's 100% device dependent - you need to consult the docs for your sound device to determine how to start the PCM.

Lee

Thanks, I see now why it starts, I'm doing some inits in my dac in the open callback... I should do those here in the trigger.

Remember that the trigger callback is designed really as a "trigger". That is, it should be executed as shortly as possible. The callback is even in the atomic context within spinlock and irq disablement, so any function that my sleep shall cause lockup.

Quoted 8 lines

If you need to allocate something, it should be done in either open, hw_params or prepare callback. Only start and stop are done in trigger callback.

Takashi

Thanks for the reminder. I think this should be ok. The only function I now have in the trigger is the following 'write' (atomic enough):
/* enable SSC data Tx */
at91_ssc_write(AT91_SSC_CR, AT91_SSC_TXEN);

Cheers,
Julien

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV