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

  • SEARCH
  • Home
  • 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 7893309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:06:01+00:00 2026-06-03T07:06:01+00:00

I’m trying to save some audio data to a WAV file — I have

  • 0

I’m trying to save some audio data to a WAV file — I have audio data that normally I’ve been using in RemoteIO but I’m now trying to implement a function to save the data. I know the audio data is valid, so that’s not a concern — if I can just get an empty WAV file set up of the correct length, I can fill it with data later.

Right now, the code creates the file and it looks to be the right length in bytes, but apparently it’s not formatted correctly, because OSX, QuickTime, iTunes, etc can’t recognize it (they see the file, can’t determine a length, or play it)

    NSURL * tvarFilename = [savePanel URL];
    NSLog(@"doSaveAs filename = %@",tvarFilename);        

    //try to create an audio file there

    AudioFileID mRecordFile;

    AudioStreamBasicDescription audioFormat;
    audioFormat.mSampleRate         = 44100.00;
    audioFormat.mFormatID           = kAudioFormatLinearPCM;
    audioFormat.mFormatFlags        = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
    audioFormat.mFramesPerPacket    = 1;
    audioFormat.mChannelsPerFrame   = 2;
    audioFormat.mBitsPerChannel     = 16;
    audioFormat.mBytesPerPacket     = 4;
    audioFormat.mBytesPerFrame      = 4;



    OSStatus status = AudioFileCreateWithURL((CFURLRef)tvarFilename, kAudioFileWAVEType, &audioFormat, kAudioFileFlags_EraseFile, &mRecordFile);

    int beatsToRecord = 4; //temporary

    int bpm = 120;

    double intervalInSamples = (double) 60 / bpm;
    intervalInSamples *= (double)44100;

    int inNumberFrames = (intervalInSamples * beatsToRecord);

    UInt32 frameBuffer[inNumberFrames];

    int sampleTime = 0;

    UInt32 thisSubBuffer[inNumberFrames];

    for (int i = 0; i < inNumberFrames; i++) { frameBuffer[i] = 0; }

    UInt32 bytesToWrite = inNumberFrames * sizeof(UInt32);
    status = AudioFileWriteBytes(mRecordFile, false, 0, &bytesToWrite, &frameBuffer);
  • 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-03T07:06:02+00:00Added an answer on June 3, 2026 at 7:06 am

    A WAV file is really simple: it only consists of a (usually 44-byte long) header section, then the raw PCM data. I’ve written a library which needs to record WAV files, and I’m pretty sure you’ll understand how I accomplish it. For clarifying:

    /**
     * CD quality: 44100 Hz sample rate, 16 bit per sample, 2 channels (stereo):
    **/
    struct sprec_wav_header *hdr = sprec_wav_header_from_params(44100, 16, 2);
    int filesize = (obtain the filesize somehow here);
    /**
     * -8 bytes for the first part of the header, see the WAV specification
    **/
    hdr->filesize = filesize - 8;
    int filedesc = open("/tmp/dummy.wav", O_WRONLY | O_CREAT, 0644);
    if (sprec_wav_header_write(filedesc, hdr))
    {
        printf("Error writing WAV header!\n");
    }
    close(filedesc);
    free(hdr);
    

    And the library I’ve written: https://github.com/H2CO3/libsprec/

    Hope this helps.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to create an if statement in PHP that prevents a single post

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.