Thanks to Yair Altman's SoundVolume.m I can control the system speaker output volume from MATLAB. However, MATLAB's sound output is still at a far lower level than, say, a random YouTube video or the test sound in the Realtek HD audio manager (latest version, 6.0.1.6080).
I'm using Windows 7, whose sound level controls are well known to be less than transparent, but MATLAB's own control in the Windows Volume Mixer is set to max -- yet MATLAB's sound level output is way less than anything else.
Any suggestions? Here is what I'm using to play a sound (a 3kHz pure tone):
Fs = 22100;
x = 0:1/Fs:1;
y = sin(2*pi*3000.*x);
wavplay(y,22100)
Have you tried increasing the amplitude?
volume = 5; % 1 is normal, 0 is mute, >1 is louder
wavplay(y*volume, 22100);
Related
I'm very new to sound. I've never explored this area in my whole life.
I thought decibels was a measure starting at 0.
But in Unity, it starts at -80db and and "0db" it seems it's the "100%" level volume.
Moreover, when I change the sound to -40db it's not "half-way" between -80db and and 0 it seems it's much closer to -80db. So the user hears nothing when it's "half-way":
I couldn't find anywhere how to setup sound properly, and how to make the user choose "properly" the sound (= good scale).
Any idea / Unity valuable sample for this?
From Wikipedia -> Decibel
dB is a relative unit of measurement [...] It expresses the ratio of two values
This is very common for Audio Mixers and Amps that 0 means 100% of the configured Pre-Gain (-> in this case the input volume of your individual AudioSources).
Why? -> The given dB are just the additional "multiplicator" (as said it is a logarithmic ratio between two values).
Usually as an Audio manager you first configure all Pre-Gains in a way that basically everything has more or less the same absolute volume if all mixer sliders are at 0.
Then you start to actually mix them according to your needs and only move certain volumes up or down to increase or decrease the volume by a certain factor. (Except for fading it is usually pretty uncommon to actually pull a slider down to the minimum - usually you rather Mute the channel)
0dB just means 1:1 => Don't change.
e.g. 6dB means about 2:1 => twice as loud as the input volume
e.g. -6dB means about 1:2 => half as loud as the input volume
e.g. 20dB means about 10:1 => Ten times as loud as the input volume
e.g. -80dB means 1:10000 => So 0.0001 of the input volume
So the -80 is chosen a little bit arbitrary .. it could as well be -60 (=>factor of 0.001) or -100 (=> factor of 0.00001). "It doesn't really matter!". At a certain point the volume is simply so low that you won't hear it anymore depending on what the default maximum output of your Amp is and how precise you need the output to be.
You can e.g. use this dB calculator to check what dB value results in what actual factor.
For a better explanation of the dB measure itself see also e.g. these posts and What's the minimum decibel value?
Im currently struggling to understand what is happening. So, I created a sound using the audiowrite function in Matlab (the sound is created using two different sounds but I dont think it matters) first with a sampling frequency of 44100 Hz, and another one, the sound file is the same but the sampling frequency is 48000 Hz. Now I'm observing that the sound produced at 44100Hz is approx. 30sec longer than the other one (48000Hz sampling). It looks like phase shifting of some sort, but I'm not sure. Any help/explanation is appreciated. I also made a amplitude/time plot for better understanding:
(I set the x axis to 350sec to see where the signal ends).
EDIT: here is the code for how I create the sound file:
[y1,F1] = audioread(cave_file); %cave and forest files are mp3 files loaded earlier both have samp.freq of 48000Hz
[y2,F2] = audioread(forest_file);
samp_freq=44100;
%samp_freq=48000;
a = max(size(y1),size(y2));
z = [[y1;zeros(abs([a(1),0]-size(y1)))],[y2;zeros(abs([a(1),0]- size(y2)))]]
audiowrite('test_sound.wav', z,samp_freq);
What is the storage format? More specifically, is the info about sampling rate and number of channels stored in file meta data? which is then used during playback.
If so, then there are 3 possibilities for this behavior:
1) The sampling rate meta data of the 44.1KHz file is incorrect, while the audio was sampled at the correct rate i.e. 44.1KHz. Because the 44.1KHz file is playing longer than 48KHz, which I'm assuming to be producing the correct sound, and playing for the correct duration, it can be concluded that the sampling rate meta data of 44.1KHz is much lesser than 44.1KHz.
Could you please check the meta data? or attach the files here so that I can try to take a look?
2) The sampling didn't happen at the correct rate, while the meta data has 44.1KHz as the sampling rate.
3) The number of channels is incorrectly stored.
In case the files are raw PCMs, then this probably the correct sampling rate and/or number of channels is not selected when playing the 44.1KHz file.
Hope this helps
In Matlab I want to hear the differences between what two waveforms sound like. What is the function used to listen to audio in Matlab? For example I have two waveforms from a file
wav1 = wavread('audio1.wav');
wav2 = wavread('audio2.wav');
how am I able to play these waveforms over my speakers?
The Matlab command to play a waveform is the sound command. it is used like so:
sound(wav1,F1);
sound(wav2,F2);
where F1 and F2 are the frequency used in playback. you can obtain the frequency from an audio file using your same wavread command thusly:
[wav1,F1,Nbits1] = wavread('audio1.wav');
where Nbits1 is the number of data points in the audio file.
Check out sound and soundsc functions.
You should try sound(wav1, 22050).
Of course, if you need higher sample rate, you can always change it.
You could use just sound(wav1) - however, you should always specify sample rate
in order to make sure you hear the waveform properly.
As far as I know when I load wav files to matlab with command:
song = wavread('file.wav');
array song have elements with values from -1 to 1. This file (and hardware) is prepared to be played with 80dB. I need to add +30dB to achieve 110dB.
I do +10dB by multiplying by sqrt(10), so to get +30dB I do:
song = song*10*sqrt(10); which is the same as
song = song*sqrt(10)*sqrt(10)*sqrt(10);
Now values of array song have much greater values than -1 to 1 and I hear distorted sound.
Is it because of this values greater than <-1,1> or quality of my speakers/headphones?
The distortion is because your values are exceeding +/-1. The float values are converted to ADC counts, which are either +/-32768 (for a 16-bit ADC) or +/-8388608 (for a right-justified 24-bit ADC) or +/-2147483648 (for a left-justfied 24-bit ADC). For a 16-bit ADC, this is usually accomplished by an operation like adcSample = (short int)(32768.0*floatSample); in C. If floatSample is > +1 or < -1 this will cause wraparound in the short int cast, which is the distortion you hear. The cast is necessary because the ADC expects 16-bit digital samples.
You will need to adjust your amplifier/speaker settings to get the sound level you desire.
Conversely, you could create a copy of your file, lower it by 30 dB, adjust your amplifier/speakers to play the new file at 80 dB, then play the original file at the same amp/speaker settings. This will cause the original file to be played at 110 dB.
As Paul R noted in his comment, I am guessing here that you are using dB as shorthand for dB SPL when referring to the actual analog sound level produced by the full signal chain.
I have an OpenAl sound engine on my iPhone app. When I play a sound that I have loaded, I can control it's pitch.
In OpenAl a pitch set to 1.0 has no effect. If you double it to 2.0, it plays the note 1 octave higher(12 semitones). If you halve it, to 0.5, it will be an octave lower (12 semitones).
So, my original sample is playing a C. I assumed that if I divide 1 by 12 (semitones) I could get the pitch for the individual notes in that octave. But this does not seem to be the case. Which makes we think that semitones are not equal values. Is that true?
Does anyone know how I can work out the openAl pitch value for individual notes in an octave?
Thank you
Semitones are equal ratios. So, if your sample is C, C# will be the 12th root of two. If you count semitones C=0, C#=1 etc, the ratio is pow(2.0, n*1.0/12.0)
Works for negative numbers, too.
I should note, this is not strictly true in every tuning scheme... but this is a good start. If you really care about the full complexities of musical tuning, I can find you some references.