📄 vxsound.cpp
字号:
if( dmab->addr == 0 ) { return -1; } dmab->area = (unsigned char *)dmab->addr; /* note: not sure where this is set with linux but seems like it should work to set here */ substream->runtime->dma_addr = dmab->addr; substream->runtime->dma_area = (unsigned char *)dmab->addr; substream->runtime->dma_buffer_p = dmab; substream->runtime->dma_bytes = size; return 0;}/** * snd_pcm_lib_preallocate_pages - pre-allocation for the given DMA type * @substream: the pcm substream instance * @type: DMA type (SNDRV_DMA_TYPE_*) * @data: DMA type dependant data * @size: the requested pre-allocation size in bytes * @max: the max. allowed pre-allocation size * * Do pre-allocation for the given DMA buffer type. * * When substream->dma_buf_id is set, the function tries to look for * the reserved buffer, and the buffer is not freed but reserved at * destruction time. The dma_buf_id must be unique for all systems * (in the same DMA buffer type) e.g. using snd_dma_pci_buf_id(). * * Returns zero if successful, or a negative error code on failure. */int snd_pcm_lib_preallocate_pages(snd_pcm_substream_t *substream, int type, struct device *data, size_t size, size_t max){ substream->dma_buffer.dev.type = type; substream->dma_buffer.dev.dev = data; return snd_pcm_lib_preallocate_pages1(substream, size, max);}/* * pre-allocate the buffer and create a proc file for the substream *//*-------------------------------------------------------------- Function Description: Allocates DMA buffer space in the passed sustream Arguments: snd_pcm_substream_t *substream - a pointer to the substream for which to free the DMA area size_t size (in bytes) Returns: 0 on success negative on failure---------------------------------------------------------------*/static int snd_pcm_lib_preallocate_pages1(snd_pcm_substream_t *substream, size_t size, size_t max){ snd_info_entry_t *entry; if (size > 0 && preallocate_dma && substream->number < maximum_substreams) vx_preallocate_pcm_pages(substream, size); if (substream->dma_buffer.bytes > 0) substream->buffer_bytes_max = substream->dma_buffer.bytes; substream->dma_max = max;#if VX_BUILD_NO_INCLUDE if ((entry = snd_info_create_card_entry(substream->pcm->card, "prealloc", substream->proc_root)) != NULL) { entry->c.text.read_size = 64; entry->c.text.read = snd_pcm_lib_preallocate_proc_read; entry->c.text.write_size = 64; entry->c.text.write = snd_pcm_lib_preallocate_proc_write; entry->mode |= S_IWUSR; entry->private_data = substream; if (snd_info_register(entry) < 0) { snd_info_free_entry(entry); entry = NULL; } } substream->proc_prealloc_entry = entry;#endif return 0;}/** * snd_pcm_lib_preallocate_pages_for_all - pre-allocation for continous memory type (all substreams) * @substream: the pcm substream instance * @type: DMA type (SNDRV_DMA_TYPE_*) * @data: DMA type dependant data * @size: the requested pre-allocation size in bytes * @max: the max. allowed pre-allocation size * * Do pre-allocation to all substreams of the given pcm for the * specified DMA type. * * Returns zero if successful, or a negative error code on failure. */int snd_pcm_lib_preallocate_pages_for_all(snd_pcm_t *pcm, int type, void *data, size_t size, size_t max){ snd_pcm_substream_t *substream; int stream, err; for (stream = 0; stream < 2; stream++) for (substream = pcm->streams[stream].substream; substream; substream = substream->next) if ((err = snd_pcm_lib_preallocate_pages(substream, type, (device *) data, size, max)) < 0) return err; return 0;}/*-------------------------------------------------------------- Function Description: This function was added for use with VxWorks. Frees the passed sound device structure and all data Arguments: void * snd_device structure to free Returns:---------------------------------------------------------------*/void vx_snd_dev_free( void *private_data ){ snd_device_t *dev = (snd_device_t *)private_data; if( dev->ops->dev_free ) { ( *dev->ops->dev_free )( dev ); } if( dev->card ) { snd_card_free( dev->card ); } kfree( dev );}/** * snd_device_new - create an ALSA device component * @card: the card instance * @type: the device type, SNDRV_DEV_TYPE_XXX * @device_data: the data pointer of this device * @ops: the operator table * * Creates a new device component for the given data pointer. * The device will be assigned to the card and managed together * by the card. * * The data pointer plays a role as the identifier, too, so the * pointer address must be unique and unchanged. * * Returns zero if successful, or a negative error code on failure. * * Note: this function is modified from the default linux function to * be passed a pointer to the pci_dev structure. This allows the * */int vx_snd_device_new(snd_card_t *card, snd_device_type_t type, void *device_data, snd_device_ops_t *ops, pci_dev *pci ){ snd_device_t *dev; snd_assert(card != NULL && device_data != NULL && ops != NULL , return -ENXIO); dev = (snd_device_t *) kcalloc(1, sizeof(*dev), GFP_KERNEL); if (dev == NULL) return -ENOMEM; dev->card = card; dev->type = type; dev->state = SNDRV_DEV_BUILD; dev->device_data = device_data; dev->ops = ops; /* these were added for use with vx works.. provide a way to free from the PCI device driver level */ pci->private_data = (void *)dev; pci->private_free = vx_snd_dev_free; return 0;}static int snd_pcm_dev_free(snd_device_t *device){ snd_pcm_t *pcm = (snd_pcm_t *)device->device_data; return snd_pcm_free(pcm);}static int snd_pcm_dev_register(snd_device_t *device){ return 0;}static int snd_pcm_dev_disconnect(snd_device_t *device){ return 0;}static int snd_pcm_dev_unregister(snd_device_t *device){ return 0;}/** * snd_pcm_new - create a new PCM instance * @card: the card instance * @id: the id string * @device: the device index (zero based) * @playback_count: the number of substreams for playback * @capture_count: the number of substreams for capture * @rpcm: the pointer to store the new pcm instance * * Creates a new PCM instance. * * The pcm operators have to be set afterwards to the new instance * via snd_pcm_set_ops(). * * Returns zero if successful, or a negative error code on failure. */int snd_pcm_new(snd_card_t * card, char *id, int device, int playback_count, int capture_count, snd_pcm_t ** rpcm){ snd_pcm_t *pcm; int err; snd_assert(rpcm != NULL, return -EINVAL); *rpcm = NULL; snd_assert(card != NULL, return -ENXIO); pcm = ( snd_pcm_t *)kcalloc(1, sizeof(*pcm), GFP_KERNEL); if (pcm == NULL) return -ENOMEM; pcm->card = card; pcm->device = device; if (id) { strlcpy(pcm->id, id, sizeof(pcm->id)); } if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) { snd_pcm_free(pcm); return err; } if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) { snd_pcm_free(pcm); return err; } init_MUTEX(&pcm->open_mutex); init_waitqueue_head(&pcm->open_wait);/* if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, ops)) < 0) { snd_pcm_free(pcm); return err; }*/ *rpcm = pcm; return 0;}/*-------------------------------------------------------------- This format data table was taken from ALSA code. Most of these formats are currently unused and may or may not actually be supported---------------------------------------------------------------*/static pcm_format_data pcm_formats[SNDRV_PCM_FORMAT_LAST+1] = { /* [SNDRV_PCM_FORMAT_S8] = */{ /*.width = */8, /*.phys =*/ 8, /*.le =*/ -1, /*.signd = */1, /*.silence = */{}, }, /* [SNDRV_PCM_FORMAT_U8] = */{ /*.width =*/ 8, /*.phys =*/ 8, /*.le = */-1, /*.signd =*/ 0, /*.silence = */{ 0x80 }, }, /* [SNDRV_PCM_FORMAT_S16_LE] = */{ /*.width =*/ 16, /*.phys =*/ 16, /*.le = */1, /*.signd =*/ 1, /*.silence =*/ {}, }, /* [SNDRV_PCM_FORMAT_S16_BE] = */{ /*.width = */16, /*.phys =*/ 16, /*.le =*/ 0, /*.signd =*/ 1, /*.silence =*/ {}, }, /* [SNDRV_PCM_FORMAT_U16_LE] = */{ /*.width =*/ 16, /*.phys = */16, /*.le = */1, /*.signd = */0, /*.silence = */{ 0x00, 0x80 }, }, /* [SNDRV_PCM_FORMAT_U16_BE] = */{ /*.width = */16, /*.phys = */16, /*.le = */0, /*.signd = */0, /*.silence = */{ 0x80, 0x00 }, }, /* [SNDRV_PCM_FORMAT_S24_LE] = */{ /*.width =*/ 24, /*.phys =*/ 32, /*.le = */1, /*.signd = */1, /*.silence = */{}, }, /* [SNDRV_PCM_FORMAT_S24_BE] = */{ /*.width = */24, /*.phys =*/ 32, /*.le = */0, /*.signd = */ 1, /*.silence = */ {}, }, /* [SNDRV_PCM_FORMAT_U24_LE] = */ { /*.width = */ 24, /*.phys = */ 32, /*.le = */ 1, /*.signd = */ 0, /*.silence = */ { 0x00, 0x00, 0x80 }, }, /* [SNDRV_PCM_FORMAT_U24_BE] = */ { /*.width = */ 24, /*.phys = */ 32, /*.le = */ 0, /*.signd = */ 0, /*.silence = */ { 0x80, 0x00, 0x00 }, }, /* [SNDRV_PCM_FORMAT_S32_LE] = */ { /*.width = */ 32, /*.phys = */ 32, /*.le = */ 1, /*.signd = */ 1, /*.silence = */ {}, }, /* [SNDRV_PCM_FORMAT_S32_BE] = */ { /*.width = */ 32, /*.phys = */ 32, /*.le = */ 0, /*.signd = */ 1, /*.silence = */ {}, }, /* [SNDRV_PCM_FORMAT_U32_LE] = */ { /*.width = */ 32, /*.phys = */ 32, /*.le = */ 1, /*.signd = */ 0, /*.silence = */ { 0x00, 0x00, 0x00, 0x80 }, }, /* [SNDRV_PCM_FORMAT_U32_BE] = */ { /*.width = */ 32, /*.phys = */ 32, /*.le = */ 0, /*.signd = */ 0, /*.silence = */ { 0x80, 0x00, 0x00, 0x00 }, }, /* [SNDRV_PCM_FORMAT_FLOAT_LE] = */ { /*.width = */ 32, /*.phys = */ 32, /*.le = */ 1, /*.signd = */ -1, /*.silence = */ {}, }, /* [SNDRV_PCM_FORMAT_FLOAT_BE] = */ { /*.width = */ 32, /*.phys = */ 32, /*.le = */ 0, /*.signd = */ -1, /*.silence = */ {}, }, /* [SNDRV_PCM_FORMAT_FLOAT64_LE] = */ { /*.width = */ 64, /*.phys = */ 64, /*.le = */ 1, /*.signd = */ -1, /*.silence = */ {}, }, /* [SNDRV_PCM_FORMAT_FLOAT64_BE] = */ { /*.width = */ 64, /*.phys = */ 64, /*.le = */ 0, /*.signd = */ -1, /*.silence = */ {}, }, /* [SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE] = */ { /*.width = */ 32, /*.phys = */ 32, /*.le = */ 1, /*.signd = */ -1, /*.silence = */ {}, }, /* [SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE] = */ { /*.width = */ 32,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -