Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8097051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:38:11+00:00 2026-06-05T21:38:11+00:00

I try to copy/write pcm-bytes (from ALSA-buffer) from the kernel-space into a file within

  • 0

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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:38:12+00:00Added an answer on June 5, 2026 at 9:38 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey I try to write a littel bash script. This should copy a dir
I try to copy SQLite database from assets directory to access it later. But
I am trying to write to copy a file by invoking a separate thread.
I'm trying to copy a file, but whatever I try, the copy seems to
I have the problem that when I try to copy some files from php
I'm desperately trying to copy a file to the sdcard from my raw folder,
I need to create an exact copy of .xls or .xlsx file from Java
I need to write the content of an array into a file. Let's suppose
I'm trying to copy the server example from http://live.gnome.org/Vala/GIONetworkingSample . But when I try
I want to copy a file from /data/data... to the external SDCARD! However, i'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.