I try to copy/write pcm-bytes (from ALSA-buffer) from the kernel-space into a file within a kernel-module (LKM).
The file got's written and the size looks ok for me, but because it's PCM-data I can't see if it's correct (raw audio data, not readable).
My audio-players (MPlayer="Invalid seek to negative position ffffffffffffffff!", VLC, Foobar2000) fail to play my written file so I think I have a mistake in my code.
When I open the file via SCITE I see many many "NUL" and other cryted stuff (bytes ;).
Maybe one of you find a bug?
I have this script:
unsigned char *dma_area; // this is the source, an mmapped-area
int pcm_offset_bytes; // the actual offset in the dma_area
int size_bytes; // the amount of bytes to copy
struct file *target_file; // the target-file
int ret; // used in write-process below
int wrote = 0; // used in write-process below
mm_segment_t fs;
void *data; // dma_area + pcm_offset_bytes
// (..) calculate offset and size
// open the target file
target_file = filp_open("/dev/snd/pcmC0D0p_output", (O_CREAT | O_TRUNC | O_WRONLY), (S_IRWXU | S_IRWXG | S_IRWXO));
data = dma_area + pcm_offset_bytes
fs = get_fs();
set_fs (get_ds ());
if (!target_file || !target_file->f_op || !target_file->f_op->write) {
LOGI("something's missing\n");
return -EIO;
}
// loop until every byte is written
while (size_bytes > 0) {
ret = target_file->f_op->write(target_file, (char *)data, size_bytes, &target_file->f_pos);
LOGI ("wrote %d bytes to target_file@%p, return %d\n", size_bytes, target_file, ret);
if (ret <= 0)
goto done;
size_bytes -= ret;
data += ret;
wrote += ret;
}
ret = wrote;
done:
set_fs(fs);
LOGI("result %d\n", ret);
First, you aren't "supposed to" write to files within the kernel.
For the more proper question of how to play headerless raw pcm, you can use the import function of audacity.
Or use aplay
aplay some_file -t raw -f S16_LE -c 2 -r 44100
With whatever parameters are appropriate.