annotate src/portaudio/test/patest_suggested_vs_streaminfo_latency.py @ 4:e13257ea84a4

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