Raised This Month: $51 Target: $400
 12% 

VoiceHook - Developer preview of something.


Post New Thread Reply   
 
Thread Tools Display Modes
hepto
Junior Member
Join Date: Jan 2012
Old 06-04-2012 , 16:09   Re: VoiceHook - Developer preview of something.
Reply With Quote #91

need update script. server crash.
threadtools.cpp (2603) : Assertion Failed: Illegal termination of worker thread 'CNet Encrypt:0'
Assert( Assertion Failed: Illegal termination of worker thread 'CNet Encrypt:0'):.threadtools.cpp:2603
threadtools.cpp (2603) : Assertion Failed: Illegal termination of worker thread 'SteamFindServerThread'
hepto is offline
hepto
Junior Member
Join Date: Jan 2012
Old 06-11-2012 , 04:45   Re: VoiceHook - Developer preview of something.
Reply With Quote #92

SM 1.4.3, The server on Windows, and falls when someone says, please update the plugin is very necessary.

Last edited by hepto; 06-11-2012 at 04:49.
hepto is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 06-15-2012 , 01:31   Re: VoiceHook - Developer preview of something.
Reply With Quote #93

Quote:
Originally Posted by asherkin View Post
http://www.dspdimension.com/admin/pi...-using-the-ft/

Code:
void smbPitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata);

void VoiceTest::OnVoiceBroadcast(int client, char *pVoiceData, int *nSamples)
{
    float *samples = new float[*nSamples];

    for (int i = 0; i < (*nSamples * 2); i += 2)
    {
        short sample = (pVoiceData[i+1] << 8) | pVoiceData[i];
        samples[i/2] = (float)sample / 32768.0f;
    }

    smbPitchShift(2.0, *nSamples, 1024, 32, 11025.0f, samples, samples);

    for (int i = 0; i < (*nSamples * 2); i += 2)
    {
        samples[i/2] = clamp<float>(samples[i/2], -1.0f, 0.999f);

        short sample = samples[i/2] * 32768.0f;
        pVoiceData[i+1] = (sample & 0xFF00) >> 8;
        pVoiceData[i] = sample & 0xFF;
    }

    delete samples;
}
If you give me the files to compile this, i will. THis is intresting, but the tutorial on SM Dev does not support 2010 express.
Mitchell is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-22-2012 , 21:05   Re: VoiceHook - Developer preview of something.
Reply With Quote #94

Holy crap it's an update.

Linux binary is actually one revision behind the Windows one atm because I cba to build it (and it's been sitting in an obscure directory of my server for the last 4 months waiting for me to post it), the last change was Windows-only though.
__________________

Last edited by asherkin; 06-22-2012 at 21:06.
asherkin is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 06-22-2012 , 22:11   Re: VoiceHook - Developer preview of something.
Reply With Quote #95

Quote:
Originally Posted by asherkin View Post
Holy crap it's an update.

Linux binary is actually one revision behind the Windows one atm because I cba to build it (and it's been sitting in an obscure directory of my server for the last 4 months waiting for me to post it), the last change was Windows-only though.
What exactly was changed?
Mitchell is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 06-22-2012 , 22:14   Re: VoiceHook - Developer preview of something.
Reply With Quote #96

Quote:
Originally Posted by Mitchell View Post
What exactly was changed?
The Window's sig was updated, and it now handles the server using SILK correctly.
__________________
asherkin is offline
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 06-23-2012 , 03:50   Re: VoiceHook - Developer preview of something.
Reply With Quote #97

Quote:
Originally Posted by asherkin View Post
The Window's sig was updated, and it now handles the server using SILK correctly.
Back in business, thanks
__________________

Last edited by GoD-Tony; 06-23-2012 at 03:50.
GoD-Tony is offline
GoD-Tony
Veteran Member
Join Date: Jul 2005
Old 07-06-2012 , 01:06   Re: VoiceHook - Developer preview of something.
Reply With Quote #98

Quote:
Originally Posted by asherkin View Post
Code:
short sample = (pVoiceData[i+1] << 8) | pVoiceData[i];
I was still hearing a bit of static with the bad solution I was using. After some more digging, it should really be:
Code:
short sample = (pVoiceData[i+1] & 0xFF) << 8 | pVoiceData[i] & 0xFF;
__________________

Last edited by GoD-Tony; 07-08-2012 at 05:27.
GoD-Tony is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 07-10-2012 , 21:50   Re: VoiceHook - Developer preview of something.
Reply With Quote #99

Quote:
Originally Posted by asherkin View Post
http://www.dspdimension.com/admin/pi...-using-the-ft/

Code:
void smbPitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata);

void VoiceTest::OnVoiceBroadcast(int client, char *pVoiceData, int *nSamples)
{
    float *samples = new float[*nSamples];

    for (int i = 0; i < (*nSamples * 2); i += 2)
    {
        short sample = (pVoiceData[i+1] << 8) | pVoiceData[i];
        samples[i/2] = (float)sample / 32768.0f;
    }

    smbPitchShift(2.0, *nSamples, 1024, 32, 11025.0f, samples, samples);

    for (int i = 0; i < (*nSamples * 2); i += 2)
    {
        samples[i/2] = clamp<float>(samples[i/2], -1.0f, 0.999f);

        short sample = samples[i/2] * 32768.0f;
        pVoiceData[i+1] = (sample & 0xFF00) >> 8;
        pVoiceData[i] = sample & 0xFF;
    }

    delete samples;
}
I get this when trying to compile that code snippet you gave us:
Code:
1>------ Build started: Project: autogain_mm, Configuration: Release - Orange Box Valve Win32 ------
1>  autogain_mm.cpp
1>m:\scripts\mm_dev\mmsource-1-8-mmsource-1.8.7\autogain\smbPitchShift.cpp(253): error C2668: 'log' : ambiguous call to overloaded function
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(575): could be 'long double log(long double)'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(527): or       'float log(float)'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(120): or       'double log(double)'
1>          while trying to match the argument list '(long)'
I used Tony's Autogain as a base, i just replaced the code with the snippet you gave us, and included the #include "smbPitchShift.cpp" at the top.
some other forums said to replace '#include <math.h>' with '#include <cmath>'
and saw no change to the error

Last edited by Mitchell; 07-10-2012 at 21:52.
Mitchell is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 07-11-2012 , 05:36   Re: VoiceHook - Developer preview of something.
Reply With Quote #100

Quote:
Originally Posted by Mitchell View Post
I get this when trying to compile that code snippet you gave us:
Code:
1>------ Build started: Project: autogain_mm, Configuration: Release - Orange Box Valve Win32 ------
1>  autogain_mm.cpp
1>m:\scripts\mm_dev\mmsource-1-8-mmsource-1.8.7\autogain\smbPitchShift.cpp(253): error C2668: 'log' : ambiguous call to overloaded function
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(575): could be 'long double log(long double)'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(527): or       'float log(float)'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\math.h(120): or       'double log(double)'
1>          while trying to match the argument list '(long)'
I used Tony's Autogain as a base, i just replaced the code with the snippet you gave us, and included the #include "smbPitchShift.cpp" at the top.
some other forums said to replace '#include <math.h>' with '#include <cmath>'
and saw no change to the error
Here's the modified smbPitchShift.cpp I use:
Code:
/****************************************************************************
*
* NAME: smbPitchShift.cpp
* VERSION: 1.2
* HOME URL: http://www.dspdimension.com
* KNOWN BUGS: none
*
* SYNOPSIS: Routine for doing pitch shifting while maintaining
* duration using the Short Time Fourier Transform.
*
* DESCRIPTION: The routine takes a pitchShift factor value which is between 0.5
* (one octave down) and 2. (one octave up). A value of exactly 1 does not change
* the pitch. numSampsToProcess tells the routine how many samples in indata[0...
* numSampsToProcess-1] should be pitch shifted and moved to outdata[0 ...
* numSampsToProcess-1]. The two buffers can be identical (ie. it can process the
* data in-place). fftFrameSize defines the FFT frame size used for the
* processing. Typical values are 1024, 2048 and 4096. It may be any value <=
* MAX_FRAME_LENGTH but it MUST be a power of 2. osamp is the STFT
* oversampling factor which also determines the overlap between adjacent STFT
* frames. It should at least be 4 for moderate scaling ratios. A value of 32 is
* recommended for best quality. sampleRate takes the sample rate for the signal 
* in unit Hz, ie. 44100 for 44.1 kHz audio. The data passed to the routine in 
* indata[] should be in the range [-1.0, 1.0), which is also the output range 
* for the data, make sure you scale the data accordingly (for 16bit signed integers
* you would have to divide (and multiply) by 32768). 
*
* COPYRIGHT 1999-2009 Stephan M. Bernsee <smb [AT] dspdimension [DOT] com>
*
* 						The Wide Open License (WOL)
*
* Permission to use, copy, modify, distribute and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice and this license appear in all source copies. 
* THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF
* ANY KIND. See http://www.dspguru.com/wol.htm for more information.
*
*****************************************************************************/ 

#include <string.h>
#include <math.h>
#include <stdio.h>

#define M_PI 3.14159265358979323846
#define MAX_FRAME_LENGTH 8192

void smbFft(float *fftBuffer, long fftFrameSize, long sign);
double smbAtan2(double x, double y);


// -----------------------------------------------------------------------------------------------------------------


void smbPitchShift(float pitchShift, long numSampsToProcess, long fftFrameSize, long osamp, float sampleRate, float *indata, float *outdata)
/*
	Routine smbPitchShift(). See top of file for explanation
	Purpose: doing pitch shifting while maintaining duration using the Short
	Time Fourier Transform.
	Author: (c)1999-2009 Stephan M. Bernsee <smb [AT] dspdimension [DOT] com>
*/
{

	static float gInFIFO[MAX_FRAME_LENGTH];
	static float gOutFIFO[MAX_FRAME_LENGTH];
	static float gFFTworksp[2*MAX_FRAME_LENGTH];
	static float gLastPhase[MAX_FRAME_LENGTH/2+1];
	static float gSumPhase[MAX_FRAME_LENGTH/2+1];
	static float gOutputAccum[2*MAX_FRAME_LENGTH];
	static float gAnaFreq[MAX_FRAME_LENGTH];
	static float gAnaMagn[MAX_FRAME_LENGTH];
	static float gSynFreq[MAX_FRAME_LENGTH];
	static float gSynMagn[MAX_FRAME_LENGTH];
	static long gRover = false, gInit = false;
	double magn, phase, tmp, window, real, imag;
	double freqPerBin, expct;
	long i,k, qpd, index, inFifoLatency, stepSize, fftFrameSize2;

	/* set up some handy variables */
	fftFrameSize2 = fftFrameSize/2;
	stepSize = fftFrameSize/osamp;
	freqPerBin = sampleRate/(double)fftFrameSize;
	expct = 2.*M_PI*(double)stepSize/(double)fftFrameSize;
	inFifoLatency = fftFrameSize-stepSize;
	if (gRover == false) gRover = inFifoLatency;

	/* initialize our static arrays */
	if (gInit == false) {
		memset(gInFIFO, 0, MAX_FRAME_LENGTH*sizeof(float));
		memset(gOutFIFO, 0, MAX_FRAME_LENGTH*sizeof(float));
		memset(gFFTworksp, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
		memset(gLastPhase, 0, (MAX_FRAME_LENGTH/2+1)*sizeof(float));
		memset(gSumPhase, 0, (MAX_FRAME_LENGTH/2+1)*sizeof(float));
		memset(gOutputAccum, 0, 2*MAX_FRAME_LENGTH*sizeof(float));
		memset(gAnaFreq, 0, MAX_FRAME_LENGTH*sizeof(float));
		memset(gAnaMagn, 0, MAX_FRAME_LENGTH*sizeof(float));
		gInit = true;
	}

	/* main processing loop */
	for (i = 0; i < numSampsToProcess; i++){

		/* As long as we have not yet collected enough data just read in */
		gInFIFO[gRover] = indata[i];
		outdata[i] = gOutFIFO[gRover-inFifoLatency];
		gRover++;

		/* now we have enough data for processing */
		if (gRover >= fftFrameSize) {
			gRover = inFifoLatency;

			/* do windowing and re,im interleave */
			for (k = 0; k < fftFrameSize;k++) {
				window = -.5*cos(2.*M_PI*(double)k/(double)fftFrameSize)+.5;
				gFFTworksp[2*k] = gInFIFO[k] * window;
				gFFTworksp[2*k+1] = 0.;
			}


			/* ***************** ANALYSIS ******************* */
			/* do transform */
			smbFft(gFFTworksp, fftFrameSize, -1);

			/* this is the analysis step */
			for (k = 0; k <= fftFrameSize2; k++) {

				/* de-interlace FFT buffer */
				real = gFFTworksp[2*k];
				imag = gFFTworksp[2*k+1];

				/* compute magnitude and phase */
				magn = 2.*sqrt(real*real + imag*imag);
				phase = atan2(imag,real);

				/* compute phase difference */
				tmp = phase - gLastPhase[k];
				gLastPhase[k] = phase;

				/* subtract expected phase difference */
				tmp -= (double)k*expct;

				/* map delta phase into +/- Pi interval */
				qpd = tmp/M_PI;
				if (qpd >= 0) qpd += qpd&1;
				else qpd -= qpd&1;
				tmp -= M_PI*(double)qpd;

				/* get deviation from bin frequency from the +/- Pi interval */
				tmp = osamp*tmp/(2.*M_PI);

				/* compute the k-th partials' true frequency */
				tmp = (double)k*freqPerBin + tmp*freqPerBin;

				/* store magnitude and true frequency in analysis arrays */
				gAnaMagn[k] = magn;
				gAnaFreq[k] = tmp;

			}

			/* ***************** PROCESSING ******************* */
			/* this does the actual pitch shifting */
			memset(gSynMagn, 0, fftFrameSize*sizeof(float));
			memset(gSynFreq, 0, fftFrameSize*sizeof(float));
			for (k = 0; k <= fftFrameSize2; k++) { 
				index = k*pitchShift;
				if (index <= fftFrameSize2) { 
					gSynMagn[index] += gAnaMagn[k]; 
					gSynFreq[index] = gAnaFreq[k] * pitchShift; 
				} 
			}
			
			/* ***************** SYNTHESIS ******************* */
			/* this is the synthesis step */
			for (k = 0; k <= fftFrameSize2; k++) {

				/* get magnitude and true frequency from synthesis arrays */
				magn = gSynMagn[k];
				tmp = gSynFreq[k];

				/* subtract bin mid frequency */
				tmp -= (double)k*freqPerBin;

				/* get bin deviation from freq deviation */
				tmp /= freqPerBin;

				/* take osamp into account */
				tmp = 2.*M_PI*tmp/osamp;

				/* add the overlap phase advance back in */
				tmp += (double)k*expct;

				/* accumulate delta phase to get bin phase */
				gSumPhase[k] += tmp;
				phase = gSumPhase[k];

				/* get real and imag part and re-interleave */
				gFFTworksp[2*k] = magn*cos(phase);
				gFFTworksp[2*k+1] = magn*sin(phase);
			} 

			/* zero negative frequencies */
			for (k = fftFrameSize+2; k < 2*fftFrameSize; k++) gFFTworksp[k] = 0.;

			/* do inverse transform */
			smbFft(gFFTworksp, fftFrameSize, 1);

			/* do windowing and add to output accumulator */ 
			for(k=0; k < fftFrameSize; k++) {
				window = -.5*cos(2.*M_PI*(double)k/(double)fftFrameSize)+.5;
				gOutputAccum[k] += 2.*window*gFFTworksp[2*k]/(fftFrameSize2*osamp);
			}
			for (k = 0; k < stepSize; k++) gOutFIFO[k] = gOutputAccum[k];

			/* shift accumulator */
			memmove(gOutputAccum, gOutputAccum+stepSize, fftFrameSize*sizeof(float));

			/* move input FIFO */
			for (k = 0; k < inFifoLatency; k++) gInFIFO[k] = gInFIFO[k+stepSize];
		}
	}
}

// -----------------------------------------------------------------------------------------------------------------


void smbFft(float *fftBuffer, long fftFrameSize, long sign)
/* 
	FFT routine, (C)1996 S.M.Bernsee. Sign = -1 is FFT, 1 is iFFT (inverse)
	Fills fftBuffer[0...2*fftFrameSize-1] with the Fourier transform of the
	time domain data in fftBuffer[0...2*fftFrameSize-1]. The FFT array takes
	and returns the cosine and sine parts in an interleaved manner, ie.
	fftBuffer[0] = cosPart[0], fftBuffer[1] = sinPart[0], asf. fftFrameSize
	must be a power of 2. It expects a complex input signal (see footnote 2),
	ie. when working with 'common' audio signals our input signal has to be
	passed as {in[0],0.,in[1],0.,in[2],0.,...} asf. In that case, the transform
	of the frequencies of interest is in fftBuffer[0...fftFrameSize].
*/
{
	float wr, wi, arg, *p1, *p2, temp;
	float tr, ti, ur, ui, *p1r, *p1i, *p2r, *p2i;
	long i, bitm, j, le, le2, k;

	for (i = 2; i < 2*fftFrameSize-2; i += 2) {
		for (bitm = 2, j = 0; bitm < 2*fftFrameSize; bitm <<= 1) {
			if (i & bitm) j++;
			j <<= 1;
		}
		if (i < j) {
			p1 = fftBuffer+i; p2 = fftBuffer+j;
			temp = *p1; *(p1++) = *p2;
			*(p2++) = temp; temp = *p1;
			*p1 = *p2; *p2 = temp;
		}
	}
	for (k = 0, le = 2; k < (long)(log((float)fftFrameSize)/log(2.)+.5); k++) {
		le <<= 1;
		le2 = le>>1;
		ur = 1.0;
		ui = 0.0;
		arg = M_PI / (le2>>1);
		wr = cos(arg);
		wi = sign*sin(arg);
		for (j = 0; j < le2; j += 2) {
			p1r = fftBuffer+j; p1i = p1r+1;
			p2r = p1r+le2; p2i = p2r+1;
			for (i = j; i < 2*fftFrameSize; i += le) {
				tr = *p2r * ur - *p2i * ui;
				ti = *p2r * ui + *p2i * ur;
				*p2r = *p1r - tr; *p2i = *p1i - ti;
				*p1r += tr; *p1i += ti;
				p1r += le; p1i += le;
				p2r += le; p2i += le;
			}
			tr = ur*wr - ui*wi;
			ui = ur*wi + ui*wr;
			ur = tr;
		}
	}
}


// -----------------------------------------------------------------------------------------------------------------

/*

    12/12/02, smb
    
    PLEASE NOTE:
    
    There have been some reports on domain errors when the atan2() function was used
    as in the above code. Usually, a domain error should not interrupt the program flow
    (maybe except in Debug mode) but rather be handled "silently" and a global variable
    should be set according to this error. However, on some occasions people ran into
    this kind of scenario, so a replacement atan2() function is provided here.
    
    If you are experiencing domain errors and your program stops, simply replace all
    instances of atan2() with calls to the smbAtan2() function below.
    
*/


double smbAtan2(double x, double y)
{
  double signx;
  if (x > 0.) signx = 1.;  
  else signx = -1.;
  
  if (x == 0.) return 0.;
  if (y == 0.) return signx * M_PI / 2.;
  
  return atan2(x, y);
}


// -----------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------------------------------
Make sure you include it as an actual object file in the project, not just as a header.

Quote:
Originally Posted by GoD-Tony View Post
I was still hearing a bit of static with the bad solution I was using. After some more digging, it should really be:
Code:
short sample = (pVoiceData[i+1] & 0xFF) << 8 | pVoiceData[i] & 0xFF;
Copying from IRC for everyone else, this should actually be:
Code:
short sample = ((short)pVoiceData[i+1] << 8) | (pVoiceData[i] & 0xFF);
__________________
asherkin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:31.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode