Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Audio array clean-up algorithm

Status
Not open for further replies.

cbmurphy

Programmer
Oct 12, 2008
11
US
i am needing to write a program to clean up an audio signal where it is clamped to a negative value using the equation


A(i) = A(2), if i = 1
A(i-1)+A(i+1)/2, if 1<i<N
A(N-1), if i = N
where N is the total number of audio samples in 1 channel (there are 2 channels)

i need to write a subroutine for this algorithm with input from a .au file in the form:

# number_of_values_per_channel
A1(1) A2(1)
A1(2) A2(2)
A1(3) A2(3)
.
.
.
.
.
A1(N) A2(N)

and output it into another .au file

any pointers to get started?
 
here is what i have so far, still getting some error messages:
[code/]
subroutine cleanUp(arrayIn, n, arrayOut)
implicit none
integer, intent(in):: n
real, intent(in), dimension(n):: arrayIn
real, intent(out), dimension(n):: arrayOut
integer:: i = 0
do i = 1, n
arrayOut(i) = arrayIn(i)
end do
do i = 1, n
if(i = 1 .and. arrayOut(i) < 0) then
arrayOut(1) = arrayOut(2)
else if(arrayOut(i) < 0 .and. i > 1 .and. i < n) then
arrayOut(i) = (arrayOut(i-1) + arrayOut(i+1))/2
else if(arrayOut(i) < 0 .and. i = n) then
arrayOut(i) = arrayOut(i-1)
else
stop
end if
end do
end subroutine

program cleanAudio
implicit none

integer:: n = 0, i = 0
character:: dummy
integer, parameter:: max = 40000.
real, dimension(max):: array1, array2
real:: arrayOut = 0
read(*,*)dummy, n
do i = 1, n
read(*,*)array1(i), array2(i)
end do
call cleanUp(array1, n, array1Out)
call cleanUp(array2, n, array2Out)
do i = 1, n
write(*,*)array1Out(i), array2Out(i)
end do
end program
[/code]

any thoughts?
 
i now have this and it doesnt show any compiling errors:
[code/]
program cleanAudio
implicit none

integer:: n = 0, i = 0
character:: dummy
integer, parameter:: max = 40000.
real, dimension(max):: array1, array2
real, dimension(max):: array1Out, array2Out
read(*,*)dummy, n
do i = 1, n
read(*,*)array1(i), array2(i)
end do
call cleanUp(array1, n, array1Out)
call cleanUp(array2, n, array2Out)
do i = 1, n
write(*,*)array1Out(i), array2Out(i)
end do
end program

subroutine cleanUp(arrayIn, n, arrayOut)
implicit none
integer, intent(in):: n
real, intent(in), dimension(n):: arrayIn
real, intent(out), dimension(n):: arrayOut
integer:: i = 0
do i = 1, n
arrayOut(i) = arrayIn(i)
end do
do i = 1, n
if(i == 1 .and. arrayOut(i) < 0) then
arrayOut(1) = arrayOut(2)
else if(arrayOut(i) < 0 .and. i > 1 .and. i < n) then
arrayOut(i) = (arrayOut(i-1) + arrayOut(i+1))/2
else if(arrayOut(i) < 0 .and. i == n) then
arrayOut(i) = arrayOut(i-1)
else
stop
end if
end do
end subroutine
[/code]

however, after i compile it in the linux shell and redirect it to read the arrays from a file and display the new clean-up arrays i show nothing. i am also trying to eventually redirect it from one .au file into a new .au file with the clean-up arrays listed in the same fashion as the input file, but i have a feeling that is no problem once the program is actually working.
 
i think i got it, it seems to have worked now:

[code/]
program cleanAudio
implicit none

integer:: n = 0, i = 0
character:: dummy
integer, parameter:: max = 40000.
real, dimension(max):: array1, array2
real, dimension(max):: array1Out, array2Out
read(*,*)dummy, n
do i = 1, n
read(*,*)array1(i), array2(i)
end do

call cleanUp(array1, n, array1Out)
call cleanUp(array2, n, array2Out)
do i = 1, n
write(*,*)array1Out(i), array2Out(i)
end do
end program

subroutine cleanUp(arrayIn, n, arrayOut)
implicit none
integer, intent(in):: n
real, intent(in), dimension(n):: arrayIn
real, intent(out), dimension(n):: arrayOut
integer:: i = 0
do i = 1, n
arrayOut(i) = arrayIn(i)
end do
do i = 1, n
if(arrayOut(i) > 0) then
arrayOut(i) = arrayOut(i)
else if(i == 1 .and. arrayOut(i) < 0) then
arrayOut(i) = arrayOut(i+1)
else if(arrayOut(i) < 0 .and. i > 1 .and. i < n) then
arrayOut(i) = (arrayOut(i-1) + arrayOut(i+1))/2
else if(arrayOut(i) < 0 .and. i == n) then
arrayOut(i) = arrayOut(i-1)
else
arrayOut(i) = arrayOut(i)
end if
end do
end subroutine
[/code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top