Skip to content

Commit

Permalink
Merge branch 't5023' into next
Browse files Browse the repository at this point in the history
Incubates #5023.
  • Loading branch information
jcsteh committed Apr 20, 2015
2 parents bb6ea40 + 3c91f0d commit a05278b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
29 changes: 13 additions & 16 deletions nvdaHelper/local/beeps.cpp
@@ -1,7 +1,7 @@
/*
This file is a part of the NVDA project.
URL: http://www.nvda-project.org/
Copyright 2006-2010 NVDA contributers.
Copyright 2006-2015 NVDA contributers.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2.0, as published by
the Free Software Foundation.
Expand All @@ -15,26 +15,23 @@ This license can be found at:
#define _USE_MATH_DEFINES
#include <cmath>
#include "beeps.h"
using namespace std;

const double PITWO=M_PI*2;
const unsigned sampleRate=44100;
const int sampleRate=44100;
const int amplitude=14000;

unsigned generateBeep(short* buf, const float hz, const unsigned length, const unsigned char left, const unsigned char right) {
const unsigned samplesPerCycle=static_cast<unsigned int>(sampleRate/hz);
unsigned totalSamples=static_cast<unsigned int>((length/1000.0)/(1.0/sampleRate));
totalSamples+=(samplesPerCycle-(totalSamples%samplesPerCycle));
int generateBeep(short* buf, const float hz, const int length, const int left, const int right) {
const int samplesPerCycle=static_cast<int>(sampleRate/hz);
int totalSamples=static_cast<int>((length/1000.0)/(1.0/sampleRate));
totalSamples+=samplesPerCycle-(totalSamples%samplesPerCycle);
if (!buf) { //just return buffer length
return totalSamples*4;
}
const double sinFreq=PITWO/samplesPerCycle;
for (unsigned sampleNum=0; sampleNum<totalSamples; ++sampleNum) {
const short sample=static_cast<short>(min(max(sin((sampleNum%sampleRate)*sinFreq)*2,-1),1)*amplitude);
const short leftSample=static_cast<short>(sample*(left/100.0));
const short rightSample=static_cast<short>(sample*(right/100.0));
buf[sampleNum*2]=leftSample;
buf[sampleNum*2+1]=rightSample;
const double lpan=(left/100.0)*amplitude, rpan=(right/100.0)*amplitude;
const double sinFreq=(2.0*M_PI)/(sampleRate/hz); //DON'T use samplesPerCycle here
for (int sampleNum=0; sampleNum<totalSamples; ++sampleNum) {
const double sample=min(max(sin((sampleNum%sampleRate)*sinFreq)*2.0,-1.0),1.0);
buf[sampleNum*2]=static_cast<short>(sample*lpan);
buf[sampleNum*2+1]=static_cast<short>(sample*rpan);
}
return totalSamples*4;
}
}
6 changes: 3 additions & 3 deletions nvdaHelper/local/beeps.h
@@ -1,7 +1,7 @@
/*
This file is a part of the NVDA project.
URL: http://www.nvda-project.org/
Copyright 2006-2010 NVDA contributers.
Copyright 2006-2015 NVDA contributers.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2.0, as published by
the Free Software Foundation.
Expand All @@ -17,6 +17,6 @@ This license can be found at:

#include "nvdaHelperLocal.h"

unsigned generateBeep(short* buf, const float hz, const unsigned length, const unsigned char left=50, const unsigned char right = 50);
int generateBeep(short* buf, const float hz, const int length, const int left=50, const int right=50);

#endif
#endif
4 changes: 2 additions & 2 deletions source/NVDAHelper.py
Expand Up @@ -438,8 +438,8 @@ def initialize():
raise e
localLib.nvdaHelperLocal_initialize()
generateBeep=localLib.generateBeep
generateBeep.argtypes=[c_char_p,c_float,c_uint,c_ubyte,c_ubyte]
generateBeep.restype=c_uint
generateBeep.argtypes=[c_char_p,c_float,c_int,c_int,c_int]
generateBeep.restype=c_int
# Handle VBuf_getTextInRange's BSTR out parameter so that the BSTR will be freed automatically.
VBuf_getTextInRange = CFUNCTYPE(c_int, c_int, c_int, c_int, POINTER(BSTR), c_int)(
("VBuf_getTextInRange", localLib),
Expand Down
2 changes: 1 addition & 1 deletion source/tones.py
Expand Up @@ -29,7 +29,7 @@ def beep(hz,length,left=50,right=50):
@param left: volume of the left channel (0 to 100)
@type left: integer
@param right: volume of the right channel (0 to 100)
@type right: float
@type right: integer
"""
log.io("Beep at pitch %s, for %s ms, left volume %s, right volume %s"%(hz,length,left,right))
if not player:
Expand Down

0 comments on commit a05278b

Please sign in to comment.