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 6380729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:18:19+00:00 2026-05-25T02:18:19+00:00

What I have done is converted a wave file to amplitude values in a

  • 0

What I have done is converted a wave file to amplitude values in a short[] array as found here Mean amplitude of a .wav in C#

I modified the values and now want to convert back to .wav format or a byte[] array which when can be written to a byte file.

  • 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-05-25T02:18:19+00:00Added an answer on May 25, 2026 at 2:18 am
    void SetShortToBuffer(short val,byte[] outArray,int Offset)
    {
        outArray[Offset] = (byte)(val & 0x00FF);
        Offset++;
        outArray[Offset] = (byte)((val >> 8) & 0x00FF);
    }
    
    byte[] ConvertShortArray(short[] Data,int Offset,int Count)
    {
        byte[] helper = new byte[Count * sizeof(short)];
    
        int end = Offset+Count;
        int io=0;
        for (int i = Offset; i < end; i++)
        {
            SetShortToBuffer(Data[i], helper, io);
            io+=sizeof(short);
        }
    
        return helper; 
    }
    

    In C this would not be an issue, you could simply tell the compiler that your previously declared short array should now be treated as a byte array (simple cast) but after failing to do so in C# outside of unsafe context I came up with this code 🙂

    You can use ConvertShortArray function to get chunks of data in case your wave is large

    EDIT:

    Quick and dirty wave header creator, not tested

    byte[] CreateWaveFileHeader(int SizeOfData, short ChannelCount, uint SamplesPerSecond, short BitsPerSample)
    {
    
        short BlockAlign = (short)(ChannelCount * (BitsPerSample / 8));
        uint AverageBytesPerSecond = SamplesPerSecond * BlockAlign;
    
        List<byte> pom = new List<byte>();
        pom.AddRange(ASCIIEncoding.ASCII.GetBytes("RIFF"));
        pom.AddRange(BitConverter.GetBytes(SizeOfData + 36)); //Size + up to data
        pom.AddRange(ASCIIEncoding.ASCII.GetBytes("WAVEfmt "));
        pom.AddRange(BitConverter.GetBytes(((uint)16))); //16 For PCM
        pom.AddRange(BitConverter.GetBytes(((short)1))); //PCM FMT
        pom.AddRange(BitConverter.GetBytes(((short)ChannelCount)));
        pom.AddRange(BitConverter.GetBytes((uint)SamplesPerSecond));
        pom.AddRange(BitConverter.GetBytes((uint)AverageBytesPerSecond));
        pom.AddRange(BitConverter.GetBytes((short)BlockAlign));
        pom.AddRange(BitConverter.GetBytes((short)BitsPerSample));
        pom.AddRange(ASCIIEncoding.ASCII.GetBytes("data"));
        pom.AddRange(BitConverter.GetBytes(SizeOfData));
    
        return pom.ToArray();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have done a graphics project using OpenGL and now I want to convert
Have done some research and found some stuff that may be helpful. I would
I have done some research, and majority of the examples I have found use
I have done various tests and I have found that the jQuery validate function
I have a code in which the character array is populated by integers (converted
I have a long array of ints that need to be converted to string.
I have done XML parsing before but never on a massive scale. If I'm
I have done this operation millions of times, just using the + operator! I
I Have done a site but want to redirect it to another subdomain in
I have done a hide and show of a div element, on clicking a

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.