#!/usr/bin/env python
#==============================================================================
#
#  $Id: esdtest,v 1.1.1.1 1999/07/23 16:07:44 mike Exp $
#
"""
   ESD test script: creates a sample, caches it, and plays it.
"""
#
#  Copyright (C) 1999 Michael A. Muller
#
#  Permission is granted to use, modify and redistribute this code,
#  providing that the following conditions are met:
#
#  1) This copyright/licensing notice must remain intact.
#  2) If the code is modified and redistributed, the modifications must 
#  include documentation indicating that the code has been modified.
#  3) The author(s) of this code must be indemnified and held harmless
#  against any damage resulting from the use of this code.
#
#  This code comes with ABSOLUTELY NO WARRANTEE, not even the implied 
#  warrantee of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
#
#  $Log: esdtest,v $
#  Revision 1.1.1.1  1999/07/23 16:07:44  mike
#  Python EsounD wrapper
#
#
#==============================================================================

from math import pi, sin
from array import array
import os

def makebell():

   str = array('B')
   for i in range(0, 32000):
      x = pi * i / 10.0
      byte = int(sin(x) * 120 * (32000 - i) / 32000 + 120)
      str.append(byte)
   return str.tostring()

import esd

print 'generating bell sample'
bellwave = esd.Sample(esd.ESD_PLAY | esd.ESD_MONO | esd.ESD_BITS8,
                      esd.ESD_DEFAULT_RATE / 4,
                      makebell()
		      )

print 'connecting to daemon'
s = esd.ServerSession('localhost')

print 'caching bell sample in server'
sampleId = s.cacheSample(bellwave, 'pyesd bell sample')

print 'playing sample'
s.playSample(sampleId)

print 'freeing sample'
s.freeSample(sampleId)

print 'done!'


