Fortraneries/SoundBrotching/soundbrotch.f90

87 lines
2.6 KiB
Fortran
Raw Normal View History

2022-02-07 23:17:22 +01:00
module soundbrotch
implicit none
2022-03-31 22:14:11 +02:00
! ---------------------------------------------------------
2022-05-05 06:58:45 +02:00
type t_sample2i
2022-03-31 22:14:11 +02:00
integer :: left
integer :: right
end type
! ---------------------------------------------------------
2022-05-23 11:11:09 +02:00
! some private variables
integer, private :: samplerate = 48000
real, private :: diapason = 440.0
2022-02-07 23:17:22 +01:00
contains
! ---------------------------------------------------------
subroutine soundbrotch_version ()
2022-05-05 06:58:45 +02:00
write(0, '(1X,A)') "--- this is soundbrotch version alpha 666"
2022-05-23 11:11:09 +02:00
write(0, *) "--- samplerate", samplerate
write(0, *) "--- diapason ", diapason
2022-05-05 06:58:45 +02:00
end subroutine
2022-05-23 11:11:09 +02:00
! ---------------------------------------------------------
! ---------------------------------------------------------
2022-02-07 23:17:22 +01:00
2022-05-05 06:58:45 +02:00
! ---------------------------------------------------------
! premier essai, le prototype peut changer !
subroutine sinw_burst2i (dst, numbs, fra, frb, level)
integer, intent(in) :: dst ! output unit number
integer, intent(in) :: numbs ! number of sample to be made
real, intent(in) :: fra, frb ! left and right frequency
real, intent(in) :: level ! amplitude in [0..1]
integer :: idx, left, right
real :: coef
2022-05-23 11:11:09 +02:00
if (dst .NE. 6) then
STOP ' OUPS!'
endif
coef = (3.141592654 * 2.0) / real(samplerate)
2022-05-05 06:58:45 +02:00
do idx=0, numbs
left = INT(32e3 * level * sin(coef*real(idx)*fra))
right = INT(32e3 * level * sin(coef*real(idx)*frb))
2022-05-23 11:11:09 +02:00
call xper_spit_2i(left, right)
2022-05-05 06:58:45 +02:00
enddo
2022-05-23 11:11:09 +02:00
end subroutine
! ---------------------------------------------------------
! mmmm ?
subroutine silence_burst2i(nbsmpl)
integer, intent(in) :: nbsmpl
integer :: idx
do idx=0, nbsmpl
call xper_spit_2i(0, 0)
2022-05-05 06:58:45 +02:00
enddo
2022-05-23 11:11:09 +02:00
end subroutine
! ---------------------------------------------------------
! mmmm ?
subroutine xper_spit_2i(lsmpl, rsmpl)
integer, intent(in) :: lsmpl, rsmpl
integer, save :: oldl, oldr
integer :: tmpl, tmpr
tmpl = (lsmpl + oldl) / 2
tmpr = (rsmpl + oldr) / 2
print *, tmpl, tmpr
oldl = tmpl
oldr = tmpr
2022-02-07 23:17:22 +01:00
end subroutine
! ---------------------------------------------------------
2022-05-23 11:11:09 +02:00
!
function midi2freq(note)
integer, intent(in) :: note
real :: midi2freq
real :: freq
freq = (DIAPASON/32.0) * (2.0 ** (real(note - 9) / 12.0));
! write(0, *) "> ", note, freq
midi2freq = freq
2022-02-07 23:17:22 +01:00
2022-05-23 11:11:09 +02:00
end function
2022-02-07 23:17:22 +01:00
end module