summaryrefslogtreecommitdiff
path: root/map65/libm65/gen_q65_cwave.f90
blob: 2f5c126205e95436394c6bf2cdfae2e2921ec510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
module gen_q65_cwave_mod
  implicit none
contains

subroutine gen_q65_cwave(msg,ntxfreq,ntone_spacing,fsample,msgsent,cwave,nwave)

  use packjt
  use q65_encoding
  use iso_fortran_env, only: real64

  !--------------------------------------------------------------------
  ! Arguments (with correct intent and explicit types)
  !--------------------------------------------------------------------
  ! fsample is the actual sample rate in Hz
  real(real64), intent(in) :: fsample
  character*24, intent(in)  :: msg
  integer,      intent(in)  :: ntxfreq
  integer,      intent(in)  :: ntone_spacing
  character*24, intent(out) :: msgsent
  complex,      intent(out) :: cwave(:)
  integer,      intent(out) :: nwave

  !--------------------------------------------------------------------
  ! Local character variables
  !--------------------------------------------------------------------
  character*37 :: msg37,msgsent37

  !--------------------------------------------------------------------
  ! Explicit declarations for all formerly implicit variables
  !--------------------------------------------------------------------
  ! Implicit REAL(4) variables (A–H, O–Z)
  real(real64) :: t, dt, phi, f, f0, dfgen, dphi, twopi, tsym, xphi

  ! Implicit INTEGER variables (I–N)
  integer :: i, j, j0, nsym

  ! Explicit locals
  integer :: codeword(65), itone(85)
  integer :: icos7(0:6)
  logical :: success

  data icos7 /2,5,6,0,4,1,3/
  data twopi /6.283185307179586476d0/
  save

  !--------------------------------------------------------------------
  ! Begin logic (unchanged from legacy)
  !--------------------------------------------------------------------
  msg37 = ''
  msg37(1:24) = msg

  call get_q65_tones(msg37, codeword, itone, msgsent37, success)
  msgsent = msgsent37(1:len(msgsent))
  if(.not.success) then
     cwave=0
     nwave=0
     return
  endif

  ! Constants
  nsym = 85
  tsym = 7200.d0 / 12000.d0          ! symbol duration (unchanged)
  dt   = 1.d0 / fsample              ! sample interval
  f0   = ntxfreq
  dfgen = ntone_spacing * 12000.d0 / 7200.d0   ! tone spacing in Hz (unchanged)

  phi = 0.d0
  dphi = twopi * dt * f0

  ! total samples for the 85-symbol Q65-60A waveform
  nwave = int( nsym * tsym * fsample + 0.5d0 )

  t = 0.d0
  j0 = 0

  do i = 1, nwave
     t = t + dt
     j = min(nsym, int(t/tsym) + 1)

     if (j /= j0) then
        f = f0 + itone(j) * dfgen
        dphi = twopi * dt * f
        j0 = j
     endif

     phi = phi + dphi
     if (phi > twopi) phi = phi - twopi

     xphi = phi
     cwave(i) = cmplx(cos(xphi), -sin(xphi))
  enddo

end subroutine gen_q65_cwave

end module gen_q65_cwave_mod