annotate src/portaudio_20161030/test/patest_suggested_vs_streaminfo_latency.py @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 284acf908dcd
children
rev   line source
Chris@55 1 #!/usr/bin/env python
Chris@55 2 """
Chris@55 3
Chris@55 4 Run and graph the results of patest_suggested_vs_streaminfo_latency.c
Chris@55 5
Chris@55 6 Requires matplotlib for plotting: http://matplotlib.sourceforge.net/
Chris@55 7
Chris@55 8 """
Chris@55 9 import os
Chris@55 10 from pylab import *
Chris@55 11 import numpy
Chris@55 12 from matplotlib.backends.backend_pdf import PdfPages
Chris@55 13
Chris@55 14 testExeName = "PATest.exe" # rename to whatever the compiled patest_suggested_vs_streaminfo_latency.c binary is
Chris@55 15 dataFileName = "patest_suggested_vs_streaminfo_latency.csv" # code below calls the exe to generate this file
Chris@55 16
Chris@55 17 inputDeviceIndex = -1 # -1 means default
Chris@55 18 outputDeviceIndex = -1 # -1 means default
Chris@55 19 sampleRate = 44100
Chris@55 20 pdfFilenameSuffix = "_wmme"
Chris@55 21
Chris@55 22 pdfFile = PdfPages("patest_suggested_vs_streaminfo_latency_" + str(sampleRate) + pdfFilenameSuffix +".pdf") #output this pdf file
Chris@55 23
Chris@55 24
Chris@55 25 def loadCsvData( dataFileName ):
Chris@55 26 params= ""
Chris@55 27 inputDevice = ""
Chris@55 28 outputDevice = ""
Chris@55 29
Chris@55 30 startLines = file(dataFileName).readlines(1024)
Chris@55 31 for line in startLines:
Chris@55 32 if "output device" in line:
Chris@55 33 outputDevice = line.strip(" \t\n\r#")
Chris@55 34 if "input device" in line:
Chris@55 35 inputDevice = line.strip(" \t\n\r#")
Chris@55 36 params = startLines[0].strip(" \t\n\r#")
Chris@55 37
Chris@55 38 data = numpy.loadtxt(dataFileName, delimiter=",", skiprows=4).transpose()
Chris@55 39
Chris@55 40 class R(object): pass
Chris@55 41 result = R()
Chris@55 42 result.params = params
Chris@55 43 for s in params.split(','):
Chris@55 44 if "sample rate" in s:
Chris@55 45 result.sampleRate = s
Chris@55 46
Chris@55 47 result.inputDevice = inputDevice
Chris@55 48 result.outputDevice = outputDevice
Chris@55 49 result.suggestedLatency = data[0]
Chris@55 50 result.halfDuplexOutputLatency = data[1]
Chris@55 51 result.halfDuplexInputLatency = data[2]
Chris@55 52 result.fullDuplexOutputLatency = data[3]
Chris@55 53 result.fullDuplexInputLatency = data[4]
Chris@55 54 return result;
Chris@55 55
Chris@55 56
Chris@55 57 def setFigureTitleAndAxisLabels( framesPerBufferString ):
Chris@55 58 title("PortAudio suggested (requested) vs. resulting (reported) stream latency\n" + framesPerBufferString)
Chris@55 59 ylabel("PaStreamInfo::{input,output}Latency (s)")
Chris@55 60 xlabel("Pa_OpenStream suggestedLatency (s)")
Chris@55 61 grid(True)
Chris@55 62 legend(loc="upper left")
Chris@55 63
Chris@55 64 def setDisplayRangeSeconds( maxSeconds ):
Chris@55 65 xlim(0, maxSeconds)
Chris@55 66 ylim(0, maxSeconds)
Chris@55 67
Chris@55 68
Chris@55 69 # run the test with different frames per buffer values:
Chris@55 70
Chris@55 71 compositeTestFramesPerBufferValues = [0]
Chris@55 72 # powers of two
Chris@55 73 for i in range (1,11):
Chris@55 74 compositeTestFramesPerBufferValues.append( pow(2,i) )
Chris@55 75
Chris@55 76 # multiples of 50
Chris@55 77 for i in range (1,20):
Chris@55 78 compositeTestFramesPerBufferValues.append( i * 50 )
Chris@55 79
Chris@55 80 # 10ms buffer sizes
Chris@55 81 compositeTestFramesPerBufferValues.append( 441 )
Chris@55 82 compositeTestFramesPerBufferValues.append( 882 )
Chris@55 83
Chris@55 84 # large primes
Chris@55 85 #compositeTestFramesPerBufferValues.append( 39209 )
Chris@55 86 #compositeTestFramesPerBufferValues.append( 37537 )
Chris@55 87 #compositeTestFramesPerBufferValues.append( 26437 )
Chris@55 88
Chris@55 89 individualPlotFramesPerBufferValues = [0,64,128,256,512] #output separate plots for these
Chris@55 90
Chris@55 91 isFirst = True
Chris@55 92
Chris@55 93 for framesPerBuffer in compositeTestFramesPerBufferValues:
Chris@55 94 commandString = testExeName + " " + str(inputDeviceIndex) + " " + str(outputDeviceIndex) + " " + str(sampleRate) + " " + str(framesPerBuffer) + ' > ' + dataFileName
Chris@55 95 print commandString
Chris@55 96 os.system(commandString)
Chris@55 97
Chris@55 98 d = loadCsvData(dataFileName)
Chris@55 99
Chris@55 100 if isFirst:
Chris@55 101 figure(1) # title sheet
Chris@55 102 gcf().text(0.1, 0.0,
Chris@55 103 "patest_suggested_vs_streaminfo_latency\n%s\n%s\n%s\n"%(d.inputDevice,d.outputDevice,d.sampleRate))
Chris@55 104 pdfFile.savefig()
Chris@55 105
Chris@55 106
Chris@55 107 figure(2) # composite plot, includes all compositeTestFramesPerBufferValues
Chris@55 108
Chris@55 109 if isFirst:
Chris@55 110 plot( d.suggestedLatency, d.suggestedLatency, label="Suggested latency" )
Chris@55 111
Chris@55 112 plot( d.suggestedLatency, d.halfDuplexOutputLatency )
Chris@55 113 plot( d.suggestedLatency, d.halfDuplexInputLatency )
Chris@55 114 plot( d.suggestedLatency, d.fullDuplexOutputLatency )
Chris@55 115 plot( d.suggestedLatency, d.fullDuplexInputLatency )
Chris@55 116
Chris@55 117 if framesPerBuffer in individualPlotFramesPerBufferValues: # individual plots
Chris@55 118 figure( 3 + individualPlotFramesPerBufferValues.index(framesPerBuffer) )
Chris@55 119
Chris@55 120 plot( d.suggestedLatency, d.suggestedLatency, label="Suggested latency" )
Chris@55 121 plot( d.suggestedLatency, d.halfDuplexOutputLatency, label="Half-duplex output latency" )
Chris@55 122 plot( d.suggestedLatency, d.halfDuplexInputLatency, label="Half-duplex input latency" )
Chris@55 123 plot( d.suggestedLatency, d.fullDuplexOutputLatency, label="Full-duplex output latency" )
Chris@55 124 plot( d.suggestedLatency, d.fullDuplexInputLatency, label="Full-duplex input latency" )
Chris@55 125
Chris@55 126 if framesPerBuffer == 0:
Chris@55 127 framesPerBufferText = "paFramesPerBufferUnspecified"
Chris@55 128 else:
Chris@55 129 framesPerBufferText = str(framesPerBuffer)
Chris@55 130 setFigureTitleAndAxisLabels( "user frames per buffer: "+str(framesPerBufferText) )
Chris@55 131 setDisplayRangeSeconds(2.2)
Chris@55 132 pdfFile.savefig()
Chris@55 133 setDisplayRangeSeconds(0.1)
Chris@55 134 setFigureTitleAndAxisLabels( "user frames per buffer: "+str(framesPerBufferText)+" (detail)" )
Chris@55 135 pdfFile.savefig()
Chris@55 136
Chris@55 137 isFirst = False
Chris@55 138
Chris@55 139 figure(2)
Chris@55 140 setFigureTitleAndAxisLabels( "composite of frames per buffer values:\n"+str(compositeTestFramesPerBufferValues) )
Chris@55 141 setDisplayRangeSeconds(2.2)
Chris@55 142 pdfFile.savefig()
Chris@55 143 setDisplayRangeSeconds(0.1)
Chris@55 144 setFigureTitleAndAxisLabels( "composite of frames per buffer values:\n"+str(compositeTestFramesPerBufferValues)+" (detail)" )
Chris@55 145 pdfFile.savefig()
Chris@55 146
Chris@55 147 pdfFile.close()
Chris@55 148
Chris@55 149 #uncomment this to display interactively, otherwise we just output a pdf
Chris@55 150 #show()