Click here to Skip to main content
15,886,833 members
Articles / Desktop Programming / WTL

Multidevice ASIO output plugin for WinAMP

Rate me:
Please Sign up or sign in to vote.
4.80/5 (9 votes)
13 Feb 2009CDDL27 min read 48.1K   728   23  
A tiny WinAMP output DLL that uses a C++ replacement of the official ASIO SDK that supports multiple ASIO devices.
// memory.cpp

// based on:
// LIBCTINY - Matt Pietrek 2001
// MSDN Magazine, January 2001

// 08/13/06 (mv)
#include <windows.h>
#include <string.h>
#include "libct.h"

#include <cassert>

BEGIN_EXTERN_C

int _resetstkoflw()
{
    HMODULE const hMSVCRT( ::LoadLibrary( "msvcrt.dll" ) );
    assert( hMSVCRT );
    typedef int ( __cdecl * Resetstkoflw )();
    Resetstkoflw pResetstkoflw( reinterpret_cast<Resetstkoflw>( ::GetProcAddress( hMSVCRT, "_resetstkofl" ) ) );
    assert( pResetstkoflw );
    int const result( pResetstkoflw ? pResetstkoflw() : false );
    ::FreeLibrary( hMSVCRT );
    return result;
}


__declspec(selectany) extern DWORD const __sse2_available
(
    ( _M_IX86_FP >= 2 )
        ? true
        : ::IsProcessorFeaturePresent( PF_XMMI64_INSTRUCTIONS_AVAILABLE )
);


#if 0 // Disabled for MSVC asm implementations.
#pragma function(memcmp)
int memcmp(const void *b1, const void *b2, size_t n)
{
	const unsigned char *p1 = (const unsigned char*)b1;
	const unsigned char *p2 = (const unsigned char*)b2;

	if (!n)
		return 0;
	for (size_t i = 0; i < n; i++)
	{
		if (p1[i] != p2[i])
			return p1[i]-p2[i];
	}
	return 0;
}

#pragma function(memset)
void * __cdecl memset(void *dst, int val, size_t size)
{
	char *realdst = (char*)dst;
	for (size_t i = 0; i < size; i++)
		realdst[i] = (char)val;
	return dst;
}

#pragma function(memcpy)
void * __cdecl memcpy(void *dst, const void *src, size_t size)
{
	char *_dst = (char*)dst;
	const char *_src = (char*)src;
	for (size_t i = 0; i < size; i++)
		_dst[i] = _src[i];
	return dst;
}

void *memmove(void *dst, const void *src, size_t count)
{
	void *ret = dst;
	if (dst <= src || (char *)dst >= ((char *)src + count))
	{
		// Non-Overlapping Buffers
		// copy from lower addresses to higher addresses
		while (count--)
		{
			*(char*)dst = *(char*)src;
			dst = (char*)dst + 1;
			src = (char*)src + 1;
		}
	}
	else
	{
		// Overlapping Buffers
		// copy from higher addresses to lower addresses
		dst = (char*)dst + count - 1;
		src = (char*)src + count - 1;

		while (count--)
		{
			*(char*)dst = *(char*)src;
			dst = (char*)dst - 1;
			src = (char*)src - 1;
		}
	}

	return ret;
}
#endif // Disabled for MSVC asm implementations.


END_EXTERN_C

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Common Development and Distribution License (CDDL)


Written By
Software Developer Little Endian Ltd.
Croatia Croatia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions