Hi ,
I am trying to create a new "rate_converter". for start i am trying to create a empty converter, but facing below error:-----------------------------------
Playing WAVE '/home/Test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
aplay: set_params:1297: Unable to install hw params:
ACCESS: RW_INTERLEAVED
FORMAT: S16_LE
SUBFORMAT: STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 48000
PERIOD_TIME: (21333 21334)
PERIOD_SIZE: NONE
PERIOD_BYTES: (4092 4100)
PERIODS: (3 5)
BUFFER_TIME: (85333 85334)
BUFFER_SIZE: 4096
BUFFER_BYTES: 16384
TICK_TIME: ALL
-----------------------------------
-----------------------
pcm.sl1 {
type hw
}
pcm_slave.sl2 {
pcm sl1
rate 96000
}
pcm.rchg {
type rate
slave sl2
converter "rateconvtest"
}
-----------------------------
pcm_slave.sl2 {
pcm sl1
rate 96000
}
pcm.rchg {
type rate
slave sl2
converter "rateconvtest"
}
-----------------------------
command used is "aplay -vD rchg /home/Test.wav".
the code of the rate converter i have created is like this:-
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <stdio.h>
#include <alsa/asoundlib.h>
#include <alsa/pcm_rate.h>
static snd_pcm_uframes_t input_frames(void *obj, snd_pcm_uframes_t frames) {
printf("\nrate in frame callback %d\n", frames);
return frames ;
}
static snd_pcm_uframes_t output_frames(void *obj, snd_pcm_uframes_t frames) {
printf("\nrate out frame callback %d\n", frames );
return (snd_pcm_uframes_t)(frames * 2);
}
static void pcm_src_free(void *obj) {
}
static int pcm_src_init(void *obj, snd_pcm_rate_info_t *info) {
printf("\n rate init rate in = %d rate out = %d\n", info->in.rate, info->out.rate);
return 0;
}
static int pcm_src_adjust_pitch(void *obj, snd_pcm_rate_info_t *info) {
printf("\n rate pitch rate = %d\n", info->in.rate);
return 0;
}
static void pcm_src_reset(void *obj) {
printf("\n rate reset \n");
}
static void pcm_src_convert_s16(void *obj, int16_t *dst, unsigned int dst_frames, const int16_t *src, unsigned int src_frames) {
unsigned int count = src_frames;
printf("\n rate in s16 convert srcfrm = %d dst frm = %d \n", src_frames, dst_frames);
memcpy(dst, src, count );
memcpy(dst + count, src, count );
}
static void pcm_src_close(void *obj) {
printf("\n rate close success\n");
}
#if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
static int get_supported_rates(void *obj, unsigned int *rate_min, unsigned int *rate_max) {
*rate_min = *rate_max = 0; /* both unlimited */
printf("\n rate supoort rate success\n");
return 0;
}
static void dump(void *obj, snd_output_t *out) {
snd_output_printf(out, "Converter: lib-ratetest\n");
}
#endif
static snd_pcm_rate_ops_t pcm_src_ops = {
.close = pcm_src_close,
.init = pcm_src_init,
.free = pcm_src_free,
.reset = pcm_src_reset,
.adjust_pitch = pcm_src_adjust_pitch,
.convert_s16 = pcm_src_convert_s16,
.input_frames = input_frames,
.output_frames = output_frames,
#if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
.version = SND_PCM_RATE_PLUGIN_VERSION,
.get_supported_rates = get_supported_rates,
.dump = dump,
#endif
};
static int pcm_src_open(unsigned int version, snd_pcm_rate_ops_t *ops) {
printf("\n rate OPEN \n");
#if SND_PCM_RATE_PLUGIN_VERSION < 0x010002
if (version != SND_PCM_RATE_PLUGIN_VERSION) {
fprintf(stderr, "Invalid rate plugin version %x\n", version);
return -EINVAL;
}
#endif
#if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
if (version == 0x010001)
memcpy(ops, &pcm_src_ops, sizeof(snd_pcm_rate_old_ops_t));
else
#endif
*ops = pcm_src_ops;
printf("\n rate OPEN complete\n");
return 0;
}
int SND_PCM_RATE_PLUGIN_ENTRY(ratehardsp) (unsigned int version, void **objp, snd_pcm_rate_ops_t *ops) {
printf("\n rate ENTRY \n");
*objp = NULL;
return pcm_src_open(version, ops);
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <stdio.h>
#include <alsa/asoundlib.h>
#include <alsa/pcm_rate.h>
static snd_pcm_uframes_t input_frames(void *obj, snd_pcm_uframes_t frames) {
printf("\nrate in frame callback %d\n", frames);
return frames ;
}
static snd_pcm_uframes_t output_frames(void *obj, snd_pcm_uframes_t frames) {
printf("\nrate out frame callback %d\n", frames );
return (snd_pcm_uframes_t)(frames * 2);
}
static void pcm_src_free(void *obj) {
}
static int pcm_src_init(void *obj, snd_pcm_rate_info_t *info) {
printf("\n rate init rate in = %d rate out = %d\n", info->in.rate, info->out.rate);
return 0;
}
static int pcm_src_adjust_pitch(void *obj, snd_pcm_rate_info_t *info) {
printf("\n rate pitch rate = %d\n", info->in.rate);
return 0;
}
static void pcm_src_reset(void *obj) {
printf("\n rate reset \n");
}
static void pcm_src_convert_s16(void *obj, int16_t *dst, unsigned int dst_frames, const int16_t *src, unsigned int src_frames) {
unsigned int count = src_frames;
printf("\n rate in s16 convert srcfrm = %d dst frm = %d \n", src_frames, dst_frames);
memcpy(dst, src, count );
memcpy(dst + count, src, count );
}
static void pcm_src_close(void *obj) {
printf("\n rate close success\n");
}
#if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
static int get_supported_rates(void *obj, unsigned int *rate_min, unsigned int *rate_max) {
*rate_min = *rate_max = 0; /* both unlimited */
printf("\n rate supoort rate success\n");
return 0;
}
static void dump(void *obj, snd_output_t *out) {
snd_output_printf(out, "Converter: lib-ratetest\n");
}
#endif
static snd_pcm_rate_ops_t pcm_src_ops = {
.close = pcm_src_close,
.init = pcm_src_init,
.free = pcm_src_free,
.reset = pcm_src_reset,
.adjust_pitch = pcm_src_adjust_pitch,
.convert_s16 = pcm_src_convert_s16,
.input_frames = input_frames,
.output_frames = output_frames,
#if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
.version = SND_PCM_RATE_PLUGIN_VERSION,
.get_supported_rates = get_supported_rates,
.dump = dump,
#endif
};
static int pcm_src_open(unsigned int version, snd_pcm_rate_ops_t *ops) {
printf("\n rate OPEN \n");
#if SND_PCM_RATE_PLUGIN_VERSION < 0x010002
if (version != SND_PCM_RATE_PLUGIN_VERSION) {
fprintf(stderr, "Invalid rate plugin version %x\n", version);
return -EINVAL;
}
#endif
#if SND_PCM_RATE_PLUGIN_VERSION >= 0x010002
if (version == 0x010001)
memcpy(ops, &pcm_src_ops, sizeof(snd_pcm_rate_old_ops_t));
else
#endif
*ops = pcm_src_ops;
printf("\n rate OPEN complete\n");
return 0;
}
int SND_PCM_RATE_PLUGIN_ENTRY(ratehardsp) (unsigned int version, void **objp, snd_pcm_rate_ops_t *ops) {
printf("\n rate ENTRY \n");
*objp = NULL;
return pcm_src_open(version, ops);
}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
So , including all the printf statements, that i have added in my code, the actual output looks like this:-
--------------------------------------------------------
rate ENTRY
rate OPEN
rate OPEN complete
rate supoort rate success
Playing WAVE '/home/Test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
aplay: set_params:1297: Unable to install hw params:
ACCESS: RW_INTERLEAVED
FORMAT: S16_LE
SUBFORMAT: STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 48000
PERIOD_TIME: (21333 21334)
PERIOD_SIZE: NONE
PERIOD_BYTES: (4092 4100)
PERIODS: (3 5)
BUFFER_TIME: (85333 85334)
BUFFER_SIZE: 4096
BUFFER_BYTES: 16384
TICK_TIME: ALL
rate close success
-----------------------------------------------------
--------------------------------------------------------
rate ENTRY
rate OPEN
rate OPEN complete
rate supoort rate success
Playing WAVE '/home/Test.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo
aplay: set_params:1297: Unable to install hw params:
ACCESS: RW_INTERLEAVED
FORMAT: S16_LE
SUBFORMAT: STD
SAMPLE_BITS: 16
FRAME_BITS: 32
CHANNELS: 2
RATE: 48000
PERIOD_TIME: (21333 21334)
PERIOD_SIZE: NONE
PERIOD_BYTES: (4092 4100)
PERIODS: (3 5)
BUFFER_TIME: (85333 85334)
BUFFER_SIZE: 4096
BUFFER_BYTES: 16384
TICK_TIME: ALL
rate close success
-----------------------------------------------------
From above i see that call went successful till the ".get_supported_rates = get_supported_rates", is the definition of function "get_supported_rates()" is wrong? OR do i need to look at something else. I am using UBUNTU 16.04 for the development purpose.
please help me.
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________ Alsa-user mailing list Alsa-user@xxxxxxxxxxxxxxxxxxxxx https://lists.sourceforge.net/lists/listinfo/alsa-user