gst-launch-0.10 no syncronized audio with alsa and hdmi - gstreamer

I'm working on a imx 6DualLite.
I can't add or edit system libraries.
I have to play an audio file from hdmi and speakers.
This is the pipeline I am using:
gst-launch-0.10 filesrc location=/home/root/beep.wav ! wavparse ! audioconvert ! audioresample ! tee name=t ! queue ! alsasink t. ! queue ! volume volume=1 ! alsasink device=sysdefault:CARD=imxhdmisoc
The problem is that the audio of the speakers is not synchronized with the audio of the hdmi
I've already tried to add
... alsasink device=sysdefault:CARD=imxhdmisoc sync=TRUE

As Florian mentioned, I'm not sure you'll realistically be able to expect the outputs to be synchronized automatically.
But if you don't mind some user intervention and/or hard-coding, you could experiment with the render-delay property of each alsasink. Set the value in nanoseconds. (e.g. one second is 1000000000 nanos).
Here's a sample with video:
gst-launch-1.0 videotestsrc pattern=ball ! videoconvert ! tee name=t ! queue ! ximagesink t. ! queue ! ximagesink render-delay=1000000000

I found a solution (in my case it worked) by linking the two cards that are displayed with the command:
~ $ cat / proc / asound / cards
0 [DWHDMI]: dw-hdmi-ahb-aud - DW-HDMI
DW-HDMI rev 0x0a, irq 22
1 [sgtl5000audio]: sgtl5000-audio - sgtl5000-audio
sgtl5000-audio
2 [tda1997xaudio]: tda1997x-audio - tda1997x-audio
tda1997x-audio
By following this guide:
https://www.alsa-project.org/wiki/Asoundrc#Virtual_multi_channel_devices
I edited the file /etc/asound.conf. I do not quote the whole file (it is very long) but only the last part that I modified:
...
pcm.!default{
type plug
route_policy "average"
slave.pcm "asymed"
}
ctl.!default{
type hw
card 0
}
ctl.mixer0{
type hw
card 0
}
became
...
pcm.!default{
type plug
route_policy "average"
slave.pcm "asymed"
}
ctl.mixer0{
type hw
card 0
}
pcm.primary{
type hw
card 0
device 0
}
ctl.primary {
type hw
card 0
}
pcm.secondary{
type hw
card 1
device 0
}
ctl.secondary {
type hw
card 1
}
pcm.multi {
type multi
slaves.a.pcm "primary"
slaves.a.channels 2
slaves.b.pcm "secondary"
slaves.b.channels 2
bindings.0.slave a
bindings.0.channel 0
bindings.1.slave a
bindings.1.channel 1
bindings.2.slave b
bindings.2.channel 0
bindings.3.slave b
bindings.3.channel 1
}

Related

Is there an alternative to the fortran binary file opening option "RECORDTYPE=stream"?

I have a fortran program where I have to open a binary output file. normally one specifies.
RECL=num
However for my particular case, a file opened with that option does not work. What works is
RECORDTYPE=stream
The gfortran which i normally does not accept the second option. With the RECL option, the program works, but the data is unusable. The Intel compiler does. Intel no longer gives a free compiler and I lost the free Intel compiler I had.
I would appreciate any suggestion to write a stream with gfortran, or if someone can backup their compiler folder, put it on google drive and give me the link (hoping this is not an abuse).
I work on Ubuntu 18.04.
I paste below, a sample program I use and the data to be written to binary.
Program stndat
implicit none
integer :: iflag=0,itime=0
integer :: nlev,ihrold,nflag,icount
integer :: ihr !,iwx,delta,cld,vis
integer,dimension(1:3) :: today,now
Real :: lat,lon,iu,iv,itemp,idp,ipress
CHARACTER(len=3) :: stnid
character(len=8) :: date
character(len=10) :: time
character(len=5) :: zone
character(len=8) :: year,inst*10,hour*2
!
integer,dimension(1:8) :: values
! using keyword arguments
call date_and_time(date,time,zone,values)
!
open(1,file='tmp.txt')
write(1,'(1x,a8,2x,a10)') date,time
Program stndat
implicit none
integer :: iflag=0,itime=0
integer :: nlev,ihrold,nflag,icount
integer :: ihr !,iwx,delta,cld,vis
integer,dimension(1:3) :: today,now
Real :: lat,lon,iu,iv,itemp,idp,ipress
CHARACTER(len=3) :: stnid
character(len=8) :: date
character(len=10) :: time
character(len=5) :: zone
character(len=8) :: year,inst*10,hour*2
!
integer,dimension(1:8) :: values
! using keyword arguments
call date_and_time(date,time,zone,values)
!
open(1,file='tmp.txt')
write(1,'(1x,a8,2x,a10)') date,time
rewind(1)
read(1,'(1x,a8,2x,a10)') year,inst
close(1,status='delete')
iflag=0
itime=0
icount=1
hour = time(:2)
hour = '09'
! Open up I/O Files
Open(unit=11,file='../../Output/synop4grads.txt',status='old')
Open(unit=12,file='../../Output/Obs_out.bin',form='unformatted',recordtype='stream',status='unknown')
10 continue
! Read in the line of code
read(11,'(1x,a3,2x,f5.2,2x,f6.2,2x,i2,8(2x,f5.1))',END=40) stnid,lon,lat,ihr,iu,iv,itemp,idp,ipress
IF (iflag.EQ.0) THEN
iflag=1
ihrold=ihr
ENDIF
!
! Check to see if this is an old time group. If so, write a terminator
IF (ihrold.NE.ihr) THEN
nlev=0
write(12)stnid,lat,lon,ihr,nlev,nflag
ENDIF
! Now make ihrold equal to the current ihr
ihrold=ihr
!
! Now we can go ahead and write the report
! First, define some variables to be used in the header
itime=0.
nlev=1
nflag=1
write(12) stnid,lat,lon,ihr,nlev,nflag
!
! read in the following: itemp,idp,ipress,iu,iv,iwx,ic,icl
write(12) iu,iv,itemp,idp,ipress
! When its done writing one report, instruct the program
! to read-in the next line
go to 10
!
! When there are no more lines to read-in, the program
! goes to 40
40 continue
nlev=0
!
write(12)stnid,lat,lon,ihr,nlev,nflag
close(11)
close(12)
end
And the data
403 29.08 -9.80 01 -0.5 -3.0 24.0 16.5 496.0
441 24.43 -11.75 01 -99.0 -99.0 18.5 16.8 533.0
461 28.85 -11.10 01 -1.4 -9.9 26.0 17.7 485.0
475 31.12 -10.21 01 -1.0 -9.9 24.4 14.0 509.0
476 31.25 -10.10 01 -0.7 -6.0 24.0 14.5 -99.0
477 31.43 -11.90 01 -1.7 -49.0 -9.9 0.0 500.0

How to fix "Segmentation fault" in fortran program

I wrote this program that reads daily gridded climate model data (6 variables) from a file and uses it in further calculations. When running the pgm for a relatively short period (e.g. 5 years) it works fine, but when I want to run it for the required 30 year period I get a "Segmentation fault".
System description: Lenovo Thinkpad with Core i7 vPro with Windows 10 Pro
Program run in Fedora (64-bit) inside Oracle VM VirtualBox
After commenting out everything and checking section-by-section I found that:
everything works fine for 30 years as long as it reads 4 variables only
as soon as the 5th or 6th variable is added, the problem creeps in
alternatively, I can run it with all 6 variables but then it only works for a shorter analysis period (e.g. 22 years)
So the problem might lie with:
the statement: recl=AX*AY*4 which I borrowed from another pgm, yet changing the 4 doesn't fix it
the system I'm running the pgm on
I have tried the "ulimit -s unlimited" command suggested elsewhere, but only get the response "cannot modify limit: Operation not permitted".
File = par_query.h
integer AX,AY,startyr,endyr,AT
character pperiod*9,GCM*4
parameter(AX=162,AY=162) ! dim of GCM array
parameter(startyr=1961,endyr=1990,AT=endyr-startyr+1,
& pperiod="1961_1990")
parameter(GCM='ukmo')
File = query.f
program query
!# A FORTRAN program that reads global climate model (GCM) data to
!# be used in further calculations
!# uses parameter file: par_query.h
!# compile as: gfortran -c -mcmodel=large query.f
!# gfortran query.o
!# then run: ./a.out
! Declarations ***************************************************
implicit none
include 'par_query.h' ! parameter file
integer :: i,j,k,m,n,nn,leapa,leapb,leapc,leapn,rec1,rec2,rec3,
& rec4,rec5,rec6
integer, dimension(12) :: mdays
real :: ydays,nyears
real, dimension(AX,AY,31,12,AT) :: tmax_d,tmin_d,rain_d,rhmax_d,
& rhmin_d,u10_d
character :: ipath*43,fname1*5,fname2*3,nname*14,yyear*4,mmonth*2,
& ext1*4
! Data statements and defining characters ************************
data mdays/31,28,31,30,31,30,31,31,30,31,30,31/ ! Days in month
ydays=365. ! Days in year
nyears=real(AT) ! Analysis period (in years)
ipath="/run/media/stephan/SS_Elements/CCAM_africa/" ! Path to
! input data directory
fname1="ccam_" ! Folder where data is located #1
fname2="_b/" ! Folder where data is located #2
nname="ccam_africa_b." ! Input filename (generic part)
ext1=".dat"
leapa=0
leapb=0
leapc=0
leapn=0
! Read daily data from GCM ***************************************
do n=startyr,endyr ! Start looping through years --------------
write(yyear,'(i4.4)')n
nn=n-startyr+1
! Test for leap years
leapa=mod(n,4)
leapb=mod(n,100)
leapc=mod(n,400)
if (leapa==0) then
if (leapb==0) then
if (leapc==0) then
leapn=1
else
leapn=0
endif
else
leapn=1
endif
else
leapn=0
endif
if (leapn==1) then
mdays(2)=29
ydays=366.
else
mdays(2)=28
ydays=365.
endif
do m=1,12 ! Start looping through months --------------------
write(mmonth,'(i2.2)')m
! Reading daily data from file
print*,"Reading data for ",n,mmonth
open(101,file=ipath//fname1//GCM//fname2//nname//GCM//"."//
& yyear//mmonth//ext1,access='direct',recl=AX*AY*4)
do k=1,mdays(m) ! Start looping through days --------------
rec1=(k-1)*6+1
rec2=(k-1)*6+2
rec3=(k-1)*6+3
rec4=(k-1)*6+4
rec5=(k-1)*6+5
rec6=(k-1)*6+6
read(101,rec=rec1)((tmax_d(i,j,k,m,nn),i=1,AX),j=1,AY)
read(101,rec=rec2)((tmin_d(i,j,k,m,nn),i=1,AX),j=1,AY)
read(101,rec=rec3)((rain_d(i,j,k,m,nn),i=1,AX),j=1,AY)
read(101,rec=rec4)((rhmax_d(i,j,k,m,nn),i=1,AX),j=1,AY)
read(101,rec=rec5)((rhmin_d(i,j,k,m,nn),i=1,AX),j=1,AY)
read(101,rec=rec6)((u10_d(i,j,k,m,nn),i=1,AX),j=1,AY)
enddo ! k-loop (days) ends --------------------------------
close(101)
enddo ! m-loop (months) ends --------------------------------
enddo ! n-loop (years) ends -----------------------------------
end program query

Why OpenDDS resends same last data when DataWriter is deleted

I would like to understand why OpenDDS resends the same last data n times (where n is the number of messages already sent) when a DataWriter is deleted ?
Is that the effect of a specific QoS I have missed ?
An output of a little test I have made :
Received data ! ID = 0 Text = Hello world !
Received data ! ID = 1 Text = Hello world !
Received data ! ID = 2 Text = Hello world !
Received data ! ID = 3 Text = Hello world !
Received data ! ID = 4 Text = Hello world !
Received data ! ID = 5 Text = Hello world !
Received data ! ID = 6 Text = Hello world !
Received data ! ID = 7 Text = Hello world !
Received data ! ID = 8 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
Received data ! ID = 9 Text = Hello world !
We see clearly in that example 10 messages were sent and received by the DataReader. Then, once the DataWriter has been deleted (or during the deletion ?), appears 10 repetitions of the last message received.
Although I have no experience with OpenDDS specifically, I would like to expand on your own answer, which does not seem entirely correct to me. I base this on mechanisms described in the DDS specification.
These empty DataSample symbolized notifications of changes of states internally in OpenDDS when the DataWriter went off.
According to the DDS specification, destruction of a DataWriter results in the unregistering of all its instances. That unregistering implies a state change of the instances from ALIVE to NOT_ALIVE. These state changes are not "internal" like you wrote, but intended to be visible for anybody who is interested. Subscribing applications can be made aware of this by inspecting the instance_state field in the SampleInfo structure.
In your case, you wrote 10 instances (key values) so the destruction of the DataWriter resulted in 10 updates, each indication a change to the state of the previously published instances.
They should not be read but just be considered as notifications.
Since these updates indicate changes to the state of the instances only, the valid_data flag is cleared and indeed, their data fields should not be read. However, it is still possible to determine which instance the update is about, by invoking get_key_value() on the DataReader in question, and passing it the InstanceHandle_t found in the field instance_handle of the SampleInfo struct. If you did that, then you would notice that there would be a notification for every ID from 0 to 9 in your case.
Searching on the web, I have found the answer to my own question :
In fact, there were no data inside the DataSample. The valid_data flag is useful to identify if the DataSample has data or not.
These empty DataSample symbolized notifications of changes of states internally in OpenDDS when the DataWriter went off. They should not be read but just be considered as notifications.

Solve error: Fortran runtime error: Bad integer for item 0 in list input

I have recently changed my f90 editor to CodeBlocks for Mac OS X, and when I try to open a file located in the project folder to read the data, the next error message appears on screen when the code is run:
Fortran runtime error: Bad integer for item 0 in list input
I have introduced the same code I used to write in Windows 7 using the intel compiler for fortran and Visual Studio.
The code itself is:
subroutine read_input_data
use input_data
implicit none
integer i,j
open(UNIT=5, FILE='lifting_line_input_data.txt', STATUS='old', FORM='formatted', ACCESS='sequential')
read(5,*) C
read(5,*) U
read(5,*) alpha
read(5,*) rho
read(5,*) wake_length
read(5,*) wake_eps
read(5,*) n_chord
read(5,*) n_twist
if (n_chord .GE. n_twist ) then
i = n_chord
else
i = n_twist
end if
allocate(chord_twist(5,i))
do j = 1, i
read(5,*) chord_twist(:,j)
end do
close(5)
end subroutine read_input_data
Could you help me to solve this problem? Thank you very much.
PD. the data file is obtain from an Excel sheet saved as a .txt delimited by tabulations
! LIFTING-LINE WING
! Number of panels
6
! Free stream speed [m/s]
50
! Angle of attack [rad]
0.15
! Air density [kg/m^3]
1.225
! Wake length [m]
100
! Convergence parameter
0.01
! Number of data points given for the chord distribution
2
! Number of data points given for the twist distribution
2
! Y coord [m] ! X_LE [m] ! X_TE [m] ! Y coord [m] ! Twist [rad]
0 0 2 0 0
10 0 0.5 10 0.052359878
PD2. I have change the format of the .txt file to make it equal to the input files I had used in Visual Studio. Now the file is:
6 ! Number of panels
50 ! Free stream speed [m/s]
0.15 ! Angle of attack [rad]
1.225 ! Air density [kg/m^3]
100 ! Wake length [m]
0.01 ! Convergence parameter
2 ! Number of data points given for the chord distribution
2 ! Number of data points given for the twist distribution
0 0 2 0 0 ! Y coord [m] ! X_LE [m] ! X_TE [m] ! Y coord [m] !Twist [rad]
10 0 0.5 10 0.052359878
And now the error given at the terminal is that the file is not found. As I am a beginner in CodeBlocks, I will explain what I have done step by step because I do not find where I am wrong and I am starting to get desperate:
New Project -> Fortran application -> I indicate where I want to create the project file.
I remove the main.f95 file and I add the .f90 file with the code.
I write the code.
I save the .txt file in the same folder than all the files of the Project.
When I run the code it appears the error message of file not found.
The code is:
!************************************************
subroutine read_input_data
use input_data
implicit none
integer i,j
open(UNIT=10, FILE='lifting_line_wing_input.txt', STATUS='old', ACCESS='sequential')
read(10,*) C
read(10,*) U
read(10,*) alpha
read(10,*) rho
read(10,*) wake_length
read(10,*) wake_eps
read(10,*) n_chord
read(10,*) n_twist
if (n_chord .GE. n_twist ) then
i = n_chord
else
i = n_twist
end if
allocate(chord_twist(5,i))
do j = 1, i
read(10,*) chord_twist(:,j)
end do
close(10)
end subroutine read_input_data
!************************************************
Thank you very much for your time and help
This looks like your old system did something non-standard with exclamation marks on list-directed input.
Try reformatting your input data like
6 / number of panels
(the slash will terminate the READ).
i don't believe any fortran compiler ever automagically handled those comments.
If you want to read this file the way it is, one approach is to make each read handle the error, eg,
integer ios
ios = 1
do while(ios.ne.0)
read(unit,*,iostat=ios)c
end do
ios=1
do while(ios.ne.0)
read(unit,*,iostat=ios)u
end do
etc..
if its a one-off you could just edit the file and delete all the comments as well.

String Replacing using Sed or Awk

Cat vols.txt (This list can fluctuate depending on the vols a system might have)
$Vol01
$Vol02
$Vol03
$Vol04
$Vol04
$Vol05
$Vol06
$Vol07
$Vol08
if I do:
cat datavols.log | sed -n 's/^\$.*/vanish \\&\.acd\*\.\* -db ! \&/gp' >> workfile.txt
I get:
cat workfile.txt
vanish $Vol01.acd*.* -db ! &
vanish $Vol02.acd*.* -db ! &
vanish $Vol03.acd*.* -db ! &
vanish $Vol04.acd*.* -db ! &
vanish $Vol05.acd*.* -db ! &
vanish $Vol06.acd*.* -db ! &
vanish $Vol07.acd*.* -db ! &
vanish $Vol08.acd*.* -db ! &
I have got 4 CPUs and I want to distribute the work between them and the output should be something like:
cat workfile.txt
Run –cpu=0 vanish $Vol01.acd*.* -db ! &
Run –cpu=1 vanish $Vol02.acd*.* -db ! &
Run –cpu=2 vanish $Vol03.acd*.* -db ! &
Run –cpu=3 vanish $Vol04.acd*.* -db ! &
Run –cpu=0 vanish $Vol05.acd*.* -db ! &
Run –cpu=1 vanish $Vol06.acd*.* -db ! &
Run –cpu=2 vanish $Vol07.acd*.* -db ! &
Run –cpu=3 vanish $Vol08.acd*.* -db ! &
Kindly help me getting this. I am not sure how to have a variable iterate between 0-3 inside SED. Thanks in advance.
awk 'BEGIN{i=0}{print "Run –cpu="i " vanish "$1".acd*.* -db ! &"; i=(i+1)%4}' inputfile
will produce the output as
Run –cpu=0 vanish $Vol01.acd*.* -db ! &
Run –cpu=1 vanish $Vol02.acd*.* -db ! &
Run –cpu=2 vanish $Vol03.acd*.* -db ! &
Run –cpu=3 vanish $Vol04.acd*.* -db ! &
Run –cpu=0 vanish $Vol05.acd*.* -db ! &
Run –cpu=1 vanish $Vol06.acd*.* -db ! &
Run –cpu=2 vanish $Vol07.acd*.* -db ! &
Run –cpu=3 vanish $Vol08.acd*.* -db ! &
You can use FNR, the current line number of the file, in awk:
awk '{print "Run -cpu=" (FNR-1)%4 " vanish " $0 ".acd*.* -db | &"}' vols.txt
You can also use this simple bash script .
Total_Cpu=4
Count=0
while read line ; do
if [ $Count -eq 4 ] ;then
Count=0
fi
echo $line | sed "s/^\$.*/Run –cpu=$Count vanish \&.acd*.* -db ! \&/g" >> Output_file
Count=`expr $Count + 1`
done < Input_File
This might work for you (GNU sed):
sed -rn '1{x;s/^/0123/;x};G;s/(.*)\n(.)(.*)/Run -cpu=\2 vanish \1.acd*.* -db ! \&\n\3\2/;P;s/.*\n//;h file
Create a line with the sequence of the cpu's you want and store it in the hold space (HS).
Append the HS to the current line and using the substitute command insert the cpu number and the required strings prepping the cpu order for the next line.
Print the string then replace the amended cpu order in the HS.
sed '1 {
x;s/^/Run –cpu=3 vanish :-D.acd*.* -db ! \&/;x
}
x;y/0123/1230/;G;s/\(.*sh \)[^.]\{1,\}\(.*\)\n\(.*\)/\1\3\2/;h' YourFile
a bit like potong bt using the last line as previous reference only changing the $vol content and cpu value