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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:35:52+00:00 2026-05-27T20:35:52+00:00

Solved My code was never before used for processing signed values and as such

  • 0

Solved

My code was never before used for processing signed values and as such bytes -> short conversion was incorrectly handling the sign bit. Doing that properly solved the issue.

The question was…

I’m trying to change the volume of a PCM data stream. I can extract single channel data from a stereo file, do various silly experimental effects with the samples by skipping/duplicating them/inserting zeros/etc but I can’t seem to find a way to modify actual sample values in any way and get a sensible output.

My attempts are really simple: https://i.stack.imgur.com/CDJzi.png

  1. source audio data
  2. values – 10000
  3. values + 10000
  4. values * 0.9
  5. values * 1.1

(value = -value works fine — reverses the wave and it sounds the same)

The code to do this is equally simple (I/O uses unsigned values in range 0-65535) <– that was the problem, reading properly signed values solved the issue:

// NOTE: INVALID CODE
int sample = ...read unsigned 16 bit value from a stream...
sample -= 32768;
sample = (int)(sample * 0.9f);
sample += 32768;
...write unsigned 16 bit value to a stream...

// NOTE: VALID CODE
int sample = ...read *signed* 16 bit value from a stream...
sample = (int)(sample * 0.9f);
...write 16 bit value to a stream...

I’m trying to make the sample quieter. I’d imagine making the amplitude smaller (sample * 0.9) would result in a quieter file but both 4. and 5. above are clearly invalid. There is a similar question on SO where MusiGenesis saying he got correct results with ‘sample *= 0.75’ type of code (yes, I did experiment with other values besides 0.9 and 1.1).

The question is: am I doing something stupid or is the whole idea of multiplying by a constant wrong? I’d like the end result to be something like this: https://i.stack.imgur.com/Wspe9.png

  • 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-27T20:35:53+00:00Added an answer on May 27, 2026 at 8:35 pm

    Your 4th attempt is definitely the the correct approach. Assuming your sample range is centered around 0, multiplying each sample by another value is how you can change the volume or gain of a signal.

    In this case though, I’d guess something funny happening behind the scenes when you’re multiplying an int by a float and casting back to int. Hard to say without knowing what language you’re using, but that might be what’s causing the problem.

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

Sidebar

Related Questions

I have never written multi-threaded code before (barring a few basic backgroundworker tricks) and
SOLVED. Code has been edited to reflect solution. Given the following GridView : <asp:GridView
Update: Solved, with code I got it working, see my answer below for the
I solved Problem 10 of Project Euler with the following code, which works through
PROBLEM SOLVED! STUPID TYPO IN MY CODE! That's my method of my UIScrollView delegate:
UPDATE The issue is solved, all the code you can see works. Hello! I
I encountered an interesting thing today that I have never noticed before. It appears
I have a pretty strange HTML problem I have never experienced before. I have
I have an assignment and i need working code. Before i start i want
I'm trying to solve some Google Code Jam problems, where an input matrix is

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.