annotate src/portaudio_20140130/test/patest_suggested_vs_streaminfo_latency.py @ 81:7029a4916348

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