COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Mapping sampled sound data to the range of [-1,+1]

• Follow

```Hi all,

May i have your advise on the relation between the Native sampled sound value and Mapped sampled sound value???

How is actually the native sound is mapped to the range of [-1, + 1] ?
If it is a simple division, I should divide the native value by?

Thank you.
```
 0
Reply st 1/9/2011 4:58:04 PM

```"st " <cell_st@hotmail.com> wrote in message <igcpes\$q7\$1@fred.mathworks.com>...
> Hi all,
>
> May i have your advise on the relation between the Native sampled sound value and Mapped sampled sound value???
>
> How is actually the native sound is mapped to the range of [-1, + 1] ?
> If it is a simple division, I should divide the native value by?
>
> Thank you.

If it is simple division, then you should divide the values by their maximum, right?

e.g:

>> new_x = x./max(abs(x));

If you're playing a sound, I think you can use soundsc() and MATLAB will automatically scale the vector for you and play it.
```
 0
Reply Husam 1/9/2011 5:10:20 PM

```"st " <cell_st@hotmail.com> wrote in message <igcpes\$q7\$1@fred.mathworks.com>...
> Hi all,
>
> May i have your advise on the relation between the Native sampled sound value and Mapped sampled sound value???
>
> How is actually the native sound is mapped to the range of [-1, + 1] ?
> If it is a simple division, I should divide the native value by?
>
> Thank you.

I don't know how it's mapped, just how you can put any sound inside those limits:

AdjustedSound=Sound/max(abs(Sound))
```
 0
Reply Paulo 1/9/2011 5:10:21 PM

```"st " <cell_st@hotmail.com> wrote in message <igcpes\$q7\$1@fred.mathworks.com>...
> Hi all,
>
> May i have your advise on the relation between the Native sampled sound value and Mapped sampled sound value???
>
> How is actually the native sound is mapped to the range of [-1, + 1] ?
> If it is a simple division, I should divide the native value by?
>
> Thank you.

better and faster way

AdjustedSound=[0 length(Sound)]; %prealocation, much faster like this
MaxVal=max(abs(Sound)); %find value of the peak
AdjustedSound=Sound/MaxVal; %get ajusted value [1 -1]
```
 0
Reply Paulo 1/9/2011 5:15:05 PM

```"Paulo Silva" <paulojmdsilva@gmail.com> wrote in message <igcqep\$2ul\$1@fred.mathworks.com>...
> "st " <cell_st@hotmail.com> wrote in message <igcpes\$q7\$1@fred.mathworks.com>...
> > Hi all,
> >
> > May i have your advise on the relation between the Native sampled sound value and Mapped sampled sound value???
> >
> > How is actually the native sound is mapped to the range of [-1, + 1] ?
> > If it is a simple division, I should divide the native value by?
> >
> > Thank you.
>
> better and faster way
>
> AdjustedSound=[0 length(Sound)]; %prealocation, much faster like this
> MaxVal=max(abs(Sound)); %find value of the peak
> AdjustedSound=Sound/MaxVal; %get ajusted value [1 -1]

Don't use the Sound like I did, use another variable because Sound is an already built in function from matlab, the final division with ./ instead of / might be faster
```
 0
Reply Paulo 1/9/2011 5:22:05 PM

```"Paulo Silva" <paulojmdsilva@gmail.com> wrote in message
> AdjustedSound=[0 length(Sound)]; %prealocation, much faster like this
> MaxVal=max(abs(Sound)); %find value of the peak
> AdjustedSound=Sound/MaxVal; %get ajusted value [1 -1]

I don't think that's faster. The first line isn't preallocation either, where I think you meant to say

> AdjustedSound = zeros(size(Sound)); %prealocation, much faster like this

Preallocation is used when you want to fill a vector/matrix with elements inside a loop or through multiple steps. When you're doing that, updating the vector/matrix with a new size each time you insert new elements inside it slows down execution because each time you update the matrix, it is declared again with a new size (changing reserved memory) and then is updated. So you preallocate by specifying its size beforehand and then proceeding to fill it up without changing its size in the loop or through further steps.

What you just did is reserve memory for AdjustedSound before filling it up, as a zero matrix. But you can similarly reserve it and fill it up with Sound/MaxVal just the same, without slowing down anything. I hope I got that across in an understandable manner.
```
 0
Reply Husam 1/9/2011 5:34:04 PM

```"Husam Aldahiyat" wrote in message <igcric\$ceu\$1@fred.mathworks.com>...
> "Paulo Silva" <paulojmdsilva@gmail.com> wrote in message
> > AdjustedSound=[0 length(Sound)]; %prealocation, much faster like this
> > MaxVal=max(abs(Sound)); %find value of the peak
> > AdjustedSound=Sound/MaxVal; %get ajusted value [1 -1]
>
> I don't think that's faster. The first line isn't preallocation either, where I think you meant to say
>
> > AdjustedSound = zeros(size(Sound)); %prealocation, much faster like this
>
> Preallocation is used when you want to fill a vector/matrix with elements inside a loop or through multiple steps. When you're doing that, updating the vector/matrix with a new size each time you insert new elements inside it slows down execution because each time you update the matrix, it is declared again with a new size (changing reserved memory) and then is updated. So you preallocate by specifying its size beforehand and then proceeding to fill it up without changing its size in the loop or through further steps.
>
> What you just did is reserve memory for AdjustedSound before filling it up, as a zero matrix. But you can similarly reserve it and fill it up with Sound/MaxVal just the same, without slowing down anything. I hope I got that across in an understandable manner.

I know what preallocation is but it was a stupid mistake on that part of the code, got distracted by something lol , thank you for the explanation and for correcting the code :) much appreciated :)
```
 0
Reply Paulo 1/9/2011 5:49:04 PM

```Husam Aldahiyat you are right there was no need to preallocate, my bad

What about the division with ./ or with / ? I tested and didn't noticed much difference, can you or someone explain what is the best practice in this case?
```
 0
Reply Paulo 1/9/2011 6:14:04 PM

```On 09/01/11 10:58 AM, st wrote:

> May i have your advise on the relation between the Native sampled sound
> value and Mapped sampled sound value???
>
> How is actually the native sound is mapped to the range of [-1, + 1] ?
> If it is a simple division, I should divide the native value by?

Sorry, that transformation is undocumented, and Mathworks has not
responded to informal requests for clarification. I have not submitted a
technical case for the matter, though.

Nearly all of the native formats have the property of enumerating 2^N
possible values, for some positive integer N, but because the [-1, +1]
value range goes from negative one _exactly_ to positive one _exactly_,
the transformed range encompasses 2^N + 1 possible values. The mechanism
for mapping between 2^N and 2^N + 1 is unknown and *cannot* be exactly
reversible in a binary floating point system.
```
 0
Reply I 1/10/2011 2:36:57 AM

8 Replies
190 Views

(page loaded in 0.031 seconds)

Similiar Articles:

7/22/2012 9:04:37 PM

 Reply: